in reply to Re^2: Question about warnings and arrays
in thread Question about warnings and arrays
#!/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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Question about warnings and arrays
by james28909 (Deacon) on Aug 13, 2014 at 11:04 UTC | |
by Anonymous Monk on Aug 13, 2014 at 11:20 UTC | |
by james28909 (Deacon) on Aug 13, 2014 at 12:53 UTC | |
by choroba (Cardinal) on Aug 13, 2014 at 12:58 UTC | |
by james28909 (Deacon) on Aug 13, 2014 at 13:13 UTC | |
|