Hi james28909 , yes, I'm that guy, you know what I'm going to say :) don't nest loops, write subroutines, small subroutines, easy to debug ... naturally this code is untested but looks easier to read doesn't it :) instead of bunches of comments, subroutine names
#!/usr/bin/perl -- ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use autodie qw/ open close /; use Path::Tiny qw/ path /; Main( @ARGV ); exit( 0 ); sub Main { my( $dirname ) = @_; my @files = getFiles( $dirname ); my @pointers; for my $file ( @files ) { SolveThisProblem( $file, \@pointers ); } SpewPointers( 'temp', \@pointers ); } ## end sub Main sub SpewPointers { my( $outfile, $pointers ) = @_; my $tempfh = path( 'temp' )->openw; ## just like autodie dies o +n error my $ix = 0; for my $lines ( @$pointers ) { ++$ix; print $tempfh "Pointer$_ - $lines"; } close $tempfh; } ## end sub SpewPointers sub SeekToAbcOffset { my( $infh ) = @_; my $infhsize = -s $infh; #seek to text entry reference in file seek $infh, 6, 0; read $infh, my $buf, 2; #convert data my $abc = unpack( 'H*', $buf ); my $offset = hex( $abc ); #use text entry reference to seek to actual text and print file/proces +s info seek $infh, $offset, 0; print "\n\n$infh - size of file: $infhsize - Text is at offset: $a +bc\n\n"; return $offset; } ## end sub SeekToAbcOffset sub SolveThisProblem { my( $filename, $pointers ) = @_; use autodie qw/ open close /; open my( $infh ), '<', $filename; binmode $infh; my $offset = SeekToAbcOffset( $infh ); READER: while( read( $FILE, my $by, 1 ) ) { if( $by eq "\x00" ) { my $pos = tell( $FILE ); my $decimal_value_pointer = $pos - $offset; push @$pointers, sprintf( "%X", $decimal_value_pointer ); next READER; } elsif( $byte =~ /ff/ ) { last READER; } } ## end READER: while( read( $FILE, my $by...)) } ## end sub SolveThisProblem __END__

See also perlquote and perlrebackslash because "\x00" is equal to chr(0), ie  $by eq chr(0)


In reply to Re^3: Question about warnings and arrays by Anonymous Monk
in thread Question about warnings and arrays by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.