[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] read binary file



At 8:09 -0900 2000.12.28, nellA hciR wrote:
>i would like some guidance on reading a binary file.
>
>what i need to do is to read the file 1K at a time, convert the binary to
>hex and write the hex to an output file.

If I understand you correctly, you could try something like:

#!perl -w
my $bytes;
open BINARY, "< path:to:binary_file" or die $!;
open HEX, "> path:to:hex_file" or die $!;

while (read(BINARY, $bytes, 1024)) {
    for (map ord, split //, $bytes) {
        printf HEX '%02X', $_;
    }
}

__END__

-- 
Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Development Network    pudge@osdn.com     http://osdn.com/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org