Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: packing and unpacking

by ungalnanban (Pilgrim)
on Mar 12, 2010 at 10:00 UTC ( #828252=note: print w/ replies, xml ) Need Help??


in reply to Re: packing and unpacking
in thread packing and unpacking


I don't know the 64-bit Perl.
whether you are mentioning 64-bit processor or ...?

I am using Perl version 5.8.8

I ran the given code It shows the following error.
Invalid type 'Q' in unpack at pack.pl line 9.
--$ugum@r--


Comment on Re^2: packing and unpacking
Re^3: packing and unpacking
by spadacciniweb (Deacon) on Mar 12, 2010 at 10:14 UTC
    From perldoc -f pack:
    Q An unsigned quad value. (Quads are available only if your system supports 64-bit integer values _and_ if Perl has been compiled to support those. Causes a fatal error otherwise.)

    (($_="Mzz ojjdloobnf jt uvy5502383")=~y~b-zg2-5c96-81~a-z0-9~s)=~s~~~s; print
      I know that "perldoc -f pack"
      why it shows this error "Invalid type 'Q' "?

      --$ugum@r--
Re^3: packing and unpacking
by almut (Canon) on Mar 12, 2010 at 10:22 UTC

    You could also simply try

    my $x1 = $r << 32 | $t; printf "\nThe value is 0x%x", $x1; # 0x23400000345

    (though whether this works similarly depends of the build options of your perl)

    P.S.: What exactly do you need this for?  Maybe bigint or Math::BigInt would help.

    Update:

    use bigint; my $r = 0x234; my $t = 0x345; my $x1 = $r << 32 | $t; print $x1->as_hex;


      while(1)
      {
      print"Thankyou...."
      }
      --$ugum@r--

        BTW, note that using bigint indiscriminately can have a massive performance penalty.  So be sure to always localize it to exactly where you actually need it (by putting extra {...} blocks around those sections).

        #!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); { use bigint; # code that needs bigint my $r = 0x234; my $t = 0x345; my $x1 = $r << 32 | $t; #print $x1->as_hex; # other stuff that doesn't... # => unnecessarily slow! sub with_bigint { my $x = 1; $x = $x * 4 / 2 - 1 for 1..1000; } } # end of bigint sub no_bigint { my $x = 1; $x = $x * 4 / 2 - 1 for 1..1000; } cmpthese (-1, { with_bigint => \&with_bigint, no_bigint => \&no_bigint, }, ); __END__ Rate with_bigint no_bigint with_bigint 11.3/s -- -100% no_bigint 4073/s 35876% --

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://828252]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2015-07-07 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls