Masem has asked for the wisdom of the Perl Monks concerning the following question:
Basically, the code that I'm using is of the following (in this case, I'm reading a header consisting of 50 integers and a 150-char string):
Now, I've got two questions on this:open FILE, "<$file" or die $!; binmode FILE; my $line; read FILE, $line, 50*2 + 150*1; my @header = unpack( "s50c150", $line ); $string = join '', map{ chr($_) } @header[50..149]; # etc, etc...
where sizeof() is this hypothetical function. Is there already something available in perl, or a better way to combine these reads and unpacks?read FILE, $line, sizeof("s50c150"); unpack( "s50c150", $line );
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read() and unpacking, data size issues
by Zaxo (Archbishop) on Nov 29, 2001 at 03:30 UTC | |
|
Re: read() and unpacking, data size issues
by Albannach (Monsignor) on Nov 29, 2001 at 01:27 UTC |