in reply to File Extraction - Cont...
Apart from that, you really should set the input recorder separator variable to "AZII*" (as recommended in replies to your previous thread), because using line-oriented i/o on non-text data is just strange. Try something like this:
(Updated to add the "next unless length()" condition -- if the file begins with "AZII*", the first input record will be empty after the "chomp".)use strict; open( FILE, '1.dat') or die "1.dat: $!"; binmode FILE; $/ = "AZII*"; my $num = 0; while (<FILE>) { chomp; next unless length(); # skip the initial (empty) input record $num++; open (DES, ">out/$num.txt") or die ( "out/$num.tiff" ); binmode DES; print DES "AZII*".$_; close DES; last if ( $num == 5 ); }
You may need to play with that, e.g. if "AZII*" is supposed to be followed by a line-feed (or carriage-return + line-feed).
I don't understand why the output file names in the OP were set to "$num.txt" -- these are not text files. You say they are image files (tiff), so why not use the appropriate extension for the output files? Am I missing something in your description of the problem?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File Extraction - Cont...
by karavay (Beadle) on Sep 26, 2007 at 03:09 UTC | |
|
Re^2: File Extraction - Cont...
by karavay (Beadle) on Sep 26, 2007 at 03:19 UTC |