Link to home
Create AccountLog in
Avatar of Aphroditus
Aphroditus

asked on

Writing hex characters to file

How do I output hexademical values to a file? I would like to include a 00 hex value at the end of a file in my server. What do I need to do in Perl to achieve this?
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

$number = hex("ffff12c0");

will return the number value of the hex ffff12c0 which is 4,294,906,560

the inverse of this is

printf(lx",$number);

this will print out the hex value of number. so just print your hex value to a file

i.e
$buffer = sprintf("%lx",$number);
print FILEHANDLE $buffer;

will print your hex to the file FILEHANDLE
Or do you mean you want
  print FILEHANDLE "\x00";
?
Avatar of Aphroditus
Aphroditus

ASKER

makerp, it does not mark the end of my file with the '00' hex when I viewed it with my hex editor. Instead, it had set it to '30'...

help?
ozo,

that won't work, cos it would write SCALAR("xxxxxxxx") to the file and that is not what we want
What do you mean by SCALAR("xxxxxxxx")?
ozo,

lets say i set my cgi script to print the date to a file by using print FILEHANDLE &get_date;

then, when i add another print FILEHANDLE \x00(i want to add another 00 hex code after my date) , it would give me this in my file :

15-Mar-2000SCALAR(0x80512cc)

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
gee... didn't notice that one!
anyway, it worked! didn't know the solution was so simple!

thanks ozo!