我是 perl 的新手,我想知道为什么参数没有正确传递给子例程。另外,输出值是否正确?
use strict;
sub crc16 {
use constant POLY => $_[1];
my $crc = 0;
for my $c ( unpack 'C*', $_[0] ) {
$crc ^= $c;
for my $b ( 0 .. 7 ) {
my $carry = $crc & 1;
$crc >>= 1;
if( $carry ) {
$crc ^= POLY;
}
}
}
return $crc;
}
my $data = "1234";
my $poly = "0x8005";
printf "crc: %04x\n", crc16( $data, $poly );
谢谢!