On Thursday, May 2, 2002, at 02:45 AM, Paul Weissman wrote:
>
> what i'm trying to do is open a binary file and read from it...
>
> ---\
>
> open ( FD, $filename );
> binmode ( FD );
>
> #read two bytes
> while (read(FD, $buf, 2)) {
> # hopefully print the hex value of two bytes
> print hex($buf);
> }
i think you are confused about what hex() does.
it takes an ascii string and interprets it as if the characters repesent a
hex number.
see perldoc -f hex.
binary data would need to be handled differently.
if i assume you want to see a dump to the terminal of your data,
you would have to do the opposite of what hex() does. turn a hex number
into a string.
program 'hexdump' does this.
if you still want to do this in perl and are stuck, you could repost your
problem.
> ---/
>
> and what i'm going for here is to read some binary data in and print out
> the
> hexadecimal value of that binary data.
>
> what's happening is very different. for whatever reason, $buf is not
> being
> treated like an ordinary number... code that does what i want is:
>
> ---\
>
> $x = 0xA;
> print hex($x);
>
> ---/
>
> which prints the value '10'.
>
> what kind of datatype is $buf in the first code snippet? and can i
> convert
> it so that i can use it like $x in the second code snippet?
>
> i'm using ActivePerl (newest version) on Win2k.
>
> thanks tons!
>
> paul
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]