The bitwise aspects have been answered already. Re the overall structure of your program, you should use strict and warnings, lexical file handles, and 3-argument open. Also, read is rarely used or needed in Perl programs. Finally, you should set binmode on both files to indicate they are binary files. I suggest something like:
use strict; use warnings; my $infile = 'yourinputfilename'; my $outfile = 'youroutputfilename'; open(my $fhin, '<', $infile) or die "error: open '$infile': $!"; binmode($fhin); open(my $fhout, '>', $outfile) or die "error: open '$outfile': $!"; binmode($fhout); local $/ = \2; # make <> operator read two bytes at a time while (my $TileData = <$fhin>) { if (length($TileData) != 2) { warn "oops, file is of uneven length, last byte='$TileData'\n"; last; } # do your thing with bitwise stuff here... # my $NewTileData = ... print {$fhout} $NewTileData; }
In reply to Re: Question about binary file I/O
by eyepopslikeamosquito
in thread Question about binary file I/O
by TheMartianGeek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |