Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!usr/bin/perl -w use strict; use warnings; open (DATA, "test.txt") || die "Unable to open file: $!"; open (OUT, ">testout.txt") || die "Cannot create out file: $!"; my $line = <DATA>; my $type = substr ($line,0,2); # match first two characters in each li +ne NEWLINE: while (<DATA>) { chomp; # remove terminating newline if ($type eq "10") { # matches all record 10 print OUT "\n"; print OUT "$line\n"; last if ($type ne "10"); } # loop adds blank row above record 10 elsif ($type ne "10") { # matches all non record 10 print OUT "$line\n"; last if ($type eq "10"); } next NEWLINE; # process next line } # end while close (DATA) || die "Unable to close file: $!"; close (OUT) || die "Unable to close file: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: exiting loops
by davido (Cardinal) on Oct 27, 2004 at 22:58 UTC | |
|
Re: exiting loops
by TheEnigma (Pilgrim) on Oct 27, 2004 at 23:12 UTC | |
|
Re: exiting loops
by TedPride (Priest) on Oct 28, 2004 at 02:35 UTC |