Eradicatore has asked for the wisdom of the Perl Monks concerning the following question:
I want to read out say 1000 bytes of a file, and then scan that 100 bytes for a string. But I do NOT want to first unpack it because I'm hoping that avoiding the unpack may save some time.
Or am I fooling myself into thinking that dealing with the scalar in binary form will be any faster than unpacking and then using normal regex?
If I do unpack, what's the best way to do that?
open BIN_IN, "<test.elf"; binmode BIN_IN; read(BIN_IN, $stuff, 1000,0); if ($stuff =~ /7F/) {print "got it!\n";} @tmp = unpack("(H2)*", $stuff); foreach $h (@tmp) { print "$h "; } close BIN_IN;
Justin Eltoft
"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Way to grep binary scalar without unpacking
by ikegami (Patriarch) on Oct 04, 2007 at 18:37 UTC | |
by diotalevi (Canon) on Oct 04, 2007 at 20:21 UTC | |
by ikegami (Patriarch) on Oct 04, 2007 at 20:40 UTC | |
by mwah (Hermit) on Oct 04, 2007 at 22:35 UTC | |
by mwah (Hermit) on Oct 04, 2007 at 21:17 UTC | |
Re: Way to grep binary scalar without unpacking
by mwah (Hermit) on Oct 04, 2007 at 19:32 UTC |