in reply to Re^2: Translating ANSI C to Perl
in thread Translating ANSI C to Perl

Nah, your problem is not in the seek, but it is here:
@list = split('', $read); foreach (@list) { $key = sprintf("%s%2.2x", $key, $_); print $key, "\n"; }
In Perl, characters are not numbers, but single character strings. Instead of @list = split('', $read); you can do
@list = unpack 'C*', $read;
and proceed as you did; or rewrite the loop, for example like this:
@list = split('', $read); $key = join "", map { sprintf "%2.2x", ord } @list;
Or rewrite both, to a blend of the two:
@list = unpack 'C*', $read; $key = join "", map { sprintf "%2.2x", $_ } @list;

Replies are listed 'Best First'.
Re^4: Translating ANSI C to Perl
by otaviof (Acolyte) on Dec 04, 2006 at 12:46 UTC
    Bart,

    Now, almost everything is working :-) but I see a little difference between C code and Perl, do you help me to understand why ?

    ANSI C:
    $ sudo ./get_HW_KEY e000f030392f30322f303400fc00
    Perl:
    $ sudo perl seek.pl e000f030392f30322f303400fcc4
    best regards
      The bug is in your C code. fgets() stops after reading 13 characters and puts a NULL character into position 14, in order to ensure that your string is always properly NULL terminated. Your perl code reads all 14 characters from the file.


      TGI says moo

        I really don't know about that ... thank's
        In my perl code, I'm just considerating just 12 first chars.