princepawn has asked for the wisdom of the Perl Monks concerning the following question:
Does anyone have any input into whether I am using the right method of doing byte-level analysis of a file for bad data? Program output *precedes* the source code.
< 47 / < 99 c < 100 d < 62 > * 10 > 60 < > 99 c > 100 d > 62 >
#!/usr/bin/perl use strict; my $f = shift || die "must supply filename"; open F, $f or die "couldnt open $f: $!"; my $bytepos = shift || die "must supply bytepos"; my $offset = 4; my @range = ($bytepos-$offset .. $bytepos+$offset); my $range = @range; my $text = join '', <F>; my @substr = ($range[0]-1, $range); warn "substr @substr"; #my $chunk = substr $text, @substr; my $chunk = substr $text, $range[0]-1, $range; warn substr $chunk, 0, 20; my $format = "C" . $range; my @unpack = unpack $format, $chunk; my $normal = $range[0]; my @chunk = split //, $chunk; for (@range) { my $arydex = $_-$normal; if ($_ < $bytepos) { print '< '; } if ($_ > $bytepos) { print '> '; } if ($_ == $bytepos) { print '* '; } print unpack 'C', $chunk[$arydex]; print "\t"; print $chunk[$arydex]; print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Byte-level file inspection?
by chipmunk (Parson) on Feb 16, 2001 at 01:34 UTC | |
|
(tye)Re: Byte-level file inspection?
by tye (Sage) on Feb 16, 2001 at 01:30 UTC | |
|
Re: Byte-level file inspection?
by MeowChow (Vicar) on Feb 16, 2001 at 01:49 UTC | |
|
Re: Byte-level file inspection?
by dws (Chancellor) on Feb 16, 2001 at 01:39 UTC | |
|
Re: Byte-level file inspection?
by mirod (Canon) on Feb 16, 2001 at 11:15 UTC |