Non-textual output

R

Ryan McCoskrie

I've used perl for odd jobs with I/O before
but it's always been plain text.

How do I get integer 0 instead of integer 48
(ascii 0) into a file?
 
A

A. Sinan Unur

I've used perl for odd jobs with I/O before
but it's always been plain text.

How do I get integer 0 instead of integer 48
(ascii 0) into a file?

Your question is a little ambiguous because you do not specify what you
mean by an 'integer'.

I am going to assume you want to get a NUL character written to the
file.

#!/usr/bin/perl

use strict;
use warnings;

open my $f, '>', 'bin' or die $!;
print $f "a\0b\0c\n";
close $f or die $!;

__END__

C:\DOCUME~1\asu1\LOCALS~1\Temp> xxd bin
0000000: 6100 6200 630d 0a a.b.c..

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
S

sln

I've used perl for odd jobs with I/O before
but it's always been plain text.

How do I get integer 0 instead of integer 48
(ascii 0) into a file?

Sure you say that now, but what happens when you want (ascii -1) into a file?

-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,108
Members
47,699
Latest member
lovelybaghel

Latest Threads

Top