Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well?

by BrowserUk (Patriarch)
on Dec 04, 2011 at 14:04 UTC ( [id://941665]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well?
in thread Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well?

I have discovered the hard way, 'pack/unpack' functions for 64 bit do not operate on 32 bit machines.

I thought I'd covered that with "and (may) only support 32-bit integers.".

I was trying to put a floating point number into a "Q" format (64bit integer) but on the 32 bit machine it threw an exception.

Putting a floating point number into an integer makes no sense to me at all?

I'm surprised you got an "exception". If I try to use 'Q' on my 32-bit installation, it simply tells me that it is invalid:

c:\test>\perl32\bin\perl -wle"print pack 'Q', -1" Invalid type 'Q' in pack at -e line 1. c:\test>\perl32\bin\perl -wle"print unpack 'Q', 'abcdefghijklmnop'" Invalid type 'Q' in unpack at -e line 1.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^4: Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well?
by flexvault (Monsignor) on Dec 04, 2011 at 16:42 UTC

    I may not be explaining myself properly -- I'll try again

    Perl can show as an integer values to at least 2**49.

    email:> perl -e '$r=2**49;print "$r\n";' 562949953421312

    If I use 'seek/sysseek', I can set the disk pointer to greater than 2**32 byte location in a 32bit disk file in Unix/Linux. I was trying to save 8 octets as a pointer in network order in a database. That database could then be moved back and forth from 32 to 64 and vice/versa. I built the database/script on a 64bit Linux machine and then tried to move to a 32bit AIX machine. The database and script did not work properly.

    Thank you

    "Well done is better than well said." - Benjamin Franklin

      Updated: corrected 'D' to 'd'.

      Ah okay. I see what you mean now.

      That said, I've previously successfully pack'd >32-bit file offsets using the 'D' 'd' format. It handles files up to at least 4 Petabytes which will easily cover anything I'm going to have to deal with for the foreseeable future.

      But I appreciate that it is less portable than a network order quad.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I looked at the 'D' format, and it would work on machines that have 64bit integer hardware, but I need to support some 32 bit only machines. But you got me thinking, and I used some basic math to get what I need (I hope?).

        The following code seems to do what I need:

        use strict; use warnings; my $num4g = 2 ** 32; my $grt4g = 500_000 + $num4g ; my $start = $num4g - 50; my $no = 0; while ( 1 ) { my $no1 = Pack( $start ); my $result = UnPack( "$no1" ); if ( $start != $result ) { die "not match"; } $start++; $no++; if ( $start >= $grt4g ) { print "Okay ( $no )\n"; exit; } } sub Pack { my $input = shift; my $lower = $input % $num4g; my $upper = int ( $input / $num4g ); return ( pack("N N", $upper, $lower ) ); } sub UnPack { my $input = shift; my ( $upper, $lower ) = unpack("N N", $input); return ( ( $upper * $num4g ) + $lower ); } 1;
        I profiled the code and 'pack/unpack' sequence is about 2us/call. The 'Pack' is about 16us per call and the 'UnPack' is about 14us per call. Expensive, but I would then get network neutral code to 562TB, and that would be good.

        Do you see anything wrong with the code?

        Thank you

        "Well done is better than well said." - Benjamin Franklin

        Thanks, I look into that!

        "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 21:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found