http://www.perlmonks.org?node_id=163123

frankied has asked for the wisdom of the Perl Monks concerning the following question:

How would you pack a 64 bit int with a perl whose pack() doesn't support 'q' ? I came up with this:
sub pack64bit() { my $i=new Math::BigInt shift(); my $j=abs($i); my($int1,$int2)=(int($j/2**32)%2**32,int($j%2**32)); if ($i<0) { $int1^=-1; $int2^=-1; ++$int2; $int2%=2**32; $int1=($int1+1)%2**32 if $int2==0; } pack('NN',$int1,$int2); # or 'VV',$int2,$int1 }
...but surely there is a more elegant way ?