in reply to Re^2: reading binary data from a file
in thread reading binary data from a file
substr can be used to extract portions of other strings. It returns a string, though. If you want to treat each character of that string as a byte, you can then use unpack 'C*'.
Square brackets can be used to create anonymous arrays. The contents of the brackets are assigned to the array. The operator returns a reference to the anonymous array.
$array[2][3] gets the 4th element of the array referenced by the 2nd element of @array. perllol
All together:
my @recs; while (read($fh, my $rec, 158)) { push @recs, [ unpack 'C*', substr($rec, 22, 13) ]; } print $recs[2][3];
Since you're using unpack anyway, you can just skip over the unwanted bytes instead of using substr.
push @recs, [ unpack 'x22 C13', $rec ];
Update: Ooops, was missing the "*" in the unpack format.
|
|---|