if ($chunk == 0xffffffffffffffffffffffff)

Discussion in 'Perl Misc' started by A. Farber, Mar 2, 2004.

  1. A. Farber

    A. Farber Guest

    Hi,

    I'm trying to verify that a file (uploaded via HTTP)
    has 24 bytes with the value 0xff at some offset:

    die "sysseek to $place failed: $!"
    unless sysseek $fh, $place, SEEK_SET;
    die "sysread failed: $!"
    unless 24 == sysread $fh, $check, 24;
    unless (0xffffffffffffffffffffffff == $check) {
    printf "Checksum storage area at 0x%X is not empty", $place;
    exit;
    }

    However the condition above is never true on
    RedHat 9 with Perl 5.6.1. Any suggestions please?

    Regards
    Alex
     
    A. Farber, Mar 2, 2004
    #1
    1. Advertising

  2. In article <>,
    A. Farber <> wrote:
    :I'm trying to verify that a file (uploaded via HTTP)
    :has 24 bytes with the value 0xff at some offset:

    : unless 24 == sysread $fh, $check, 24;
    : unless (0xffffffffffffffffffffffff == $check) {

    :However the condition above is never true on
    :RedHat 9 with Perl 5.6.1. Any suggestions please?

    0xffffffffffffffffffffffff is a number that is overflowing
    the maximum integer available.

    Try unless (("\xff" x 24) == $check)
    --
    "[...] it's all part of one's right to be publicly stupid." -- Dave Smey
     
    Walter Roberson, Mar 2, 2004
    #2
    1. Advertising

  3. A. Farber

    Ben Morrow Guest

    -cnrc.gc.ca (Walter Roberson) wrote:
    > In article <>,
    > A. Farber <> wrote:
    > :I'm trying to verify that a file (uploaded via HTTP)
    > :has 24 bytes with the value 0xff at some offset:
    >
    > : unless 24 == sysread $fh, $check, 24;
    > : unless (0xffffffffffffffffffffffff == $check) {
    >
    > :However the condition above is never true on
    > :RedHat 9 with Perl 5.6.1. Any suggestions please?
    >
    > 0xffffffffffffffffffffffff is a number that is overflowing
    > the maximum integer available.
    >
    > Try unless (("\xff" x 24) == $check)

    ^^
    eq
    Ben

    --
    If you put all the prophets, | You'd have so much more reason
    Mystics and saints | Than ever was born
    In one room together, | Out of all of the conflicts of time.
    The Levellers, 'Believers'
     
    Ben Morrow, Mar 2, 2004
    #3
  4. A. Farber

    Anno Siegel Guest

    A. Farber <> wrote in comp.lang.perl.misc:
    > Hi,
    >
    > I'm trying to verify that a file (uploaded via HTTP)
    > has 24 bytes with the value 0xff at some offset:


    "24 bytes with value 0xff" can mean a few different things. Do you mean,
    each of the 24 bytes has value 0xff (255)?

    > die "sysseek to $place failed: $!"
    > unless sysseek $fh, $place, SEEK_SET;
    > die "sysread failed: $!"
    > unless 24 == sysread $fh, $check, 24;


    Why are you using sysseek(), sysread(), etc? What is your reason for not
    using standard IO functions?

    > unless (0xffffffffffffffffffffffff == $check) {


    That is a 12 byte number. Perl doesn't deal natively with numbers that
    wide (nor does anything else). But it still is only half the length of
    your 24 bytes.

    But your code wouldn't work even if you only had 4 bytes (which fit into
    a native integer on most machines). Perl reads strings from files, not
    numbers. So, if you read 24 bytes of one-bits, a string of 24 bytes of
    one-bits is what you get. Try string comparison with that value:

    $check eq "\xff" x 24;

    Anno

    > printf "Checksum storage area at 0x%X is not empty", $place;
    > exit;
    > }
    >
    > However the condition above is never true on
    > RedHat 9 with Perl 5.6.1. Any suggestions please?
    >
    > Regards
    > Alex
     
    Anno Siegel, Mar 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Daniel Gamache
    Replies:
    0
    Views:
    446
    Jean-Daniel Gamache
    Jul 14, 2004
  2. Ray Thomas
    Replies:
    1
    Views:
    3,342
    Ray Thomas
    Jul 21, 2004
  3. Lior Knaany

    Gzip each chunk separately

    Lior Knaany, Jan 2, 2006, in forum: Java
    Replies:
    9
    Views:
    1,180
    Lior Knaany
    Jan 16, 2006
  4. Rob Shepherd
    Replies:
    0
    Views:
    629
    Rob Shepherd
    Jun 9, 2005
  5. Sanjeeb
    Replies:
    3
    Views:
    448
    Ryan Kelly
    Aug 3, 2010
Loading...

Share This Page