in reply to Re^2: Translating ANSI C to Perl
in thread Translating ANSI C to Perl
In Perl, characters are not numbers, but single character strings. Instead of @list = split('', $read); you can do@list = split('', $read); foreach (@list) { $key = sprintf("%s%2.2x", $key, $_); print $key, "\n"; }
and proceed as you did; or rewrite the loop, for example like this:@list = unpack 'C*', $read;
Or rewrite both, to a blend of the two:@list = split('', $read); $key = join "", map { sprintf "%2.2x", ord } @list;
@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 | |
by TGI (Parson) on Dec 04, 2006 at 15:19 UTC | |
by otaviof (Acolyte) on Dec 05, 2006 at 02:34 UTC |