> -----Original Message-----
> From: Tyler Cruickshank [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 1:32 PM
> To: [EMAIL PROTECTED]
> Subject: binary files
>
>
> Hello.
>
> Looking for some binary file help. I want to read,
> manipulate, and print (in ascii) a binary file on a solaris 7
> machine. I have looked into and tried the binmode() function
> but this seems to be for older machines that differentiate
> between ascii and binary files. I have tried the following
> and just get the binary form printed back out at me (the
> expected result):
>
> open(FILE, "mybinaryfile") || or die "error\n";
> while(<FILE>){
> print "$_\n";
> }
>
> When perl reads a binary file as above, does it understand
> what it is reading? How can I print the file back out in ascii?
A file is a file. Perl isn't going to do anything special with your files.
It just calls your system read(2), or fread(3) calls to read a file.
A loop like you have above is suitable for reading "text" files broken into
"lines" separated by \n chars (although perl lets you define any kind of
"line" separator you want).
For data that's not divided into "lines", you can use the perl read()
function. If the data is packed into various binary formats, you can use
perl's unpack() function to decode it into individual values.
binmode is for those systems like Win32 that munge around with line endings
on "text" files. For Unix, you don't need to worry about it (although
calling binmode is harmless on Unix).
See:
perldoc read
perldoc seek
perldoc tell
perldoc sysread
perldoc unpack
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]