• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

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?
0
Aphroditus
Asked:
Aphroditus
  • 4
  • 3
1 Solution
 
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
 
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
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
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
 
ozoCommented:
#I said
  print FILEHANDLE "\x00";
#not
  print FILEHANDLE \x00;
0
 
AphroditusAuthor Commented:
gee... didn't notice that one!
anyway, it worked! didn't know the solution was so simple!

thanks ozo!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now