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?
AphroditusAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
#I said
  print FILEHANDLE "\x00";
#not
  print FILEHANDLE \x00;
0
 
makerpCommented:
$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
0
 
ozoCommented:
Or do you mean you want
  print FILEHANDLE "\x00";
?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
AphroditusAuthor Commented:
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?
0
 
AphroditusAuthor Commented:
ozo,

that won't work, cos it would write SCALAR("xxxxxxxx") to the file and that is not what we want
0
 
ozoCommented:
What do you mean by SCALAR("xxxxxxxx")?
0
 
AphroditusAuthor Commented:
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)

0
 
AphroditusAuthor Commented:
gee... didn't notice that one!
anyway, it worked! didn't know the solution was so simple!

thanks ozo!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.