Perl笔记
来自Jack's Lab
1 Catalyst 安装
$ apt-get install perl perl-modules libcatalyst-perl libcatalyst-modules-perl
2 位反转
$ cat bit-rev.pl #!/usr/bin/perl sub rev { my $in = shift; $in = ($in & 0x55555555) << 1 | ($in & 0xaaaaaaaa) >> 1; $in = ($in & 0x33333333) << 2 | ($in & 0xCCCCCCCC) >> 2; $in = ($in & 0x0f0f0f0f) << 4 | ($in & 0xf0f0f0f0) >> 4; $in = ($in & 0x00ff00ff) << 8 | ($in & 0xff00ff00) >> 8; $in = ($in & 0x0000ffff) << 16 | ($in & 0xffff0000) >> 16; return $in; } my $d = 0x80008001; printf "d = 0x%08x\n", $d; printf "rd = 0x%08x\n", &rev($d); $ ./bit-rev.pl d = 0x80008001 rd = 0x80010001
3 Resource
- Mastering Perl: http://chimera.labs.oreilly.com/books/1234000001527/index.html
- Catalyst Manual: https://metacpan.org/release/Catalyst-Manual
- meta cpan: https://metacpan.org/pod/Data::Random
- perl doc: http://perldoc.perl.org/