logo       

Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1 (Correction): msg#00044

lang.perl.qotw.discuss

Subject: Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1 (Correction)

On Mon, 24 Jan 2005, Daniel Martin wrote:

Huh. No one so far seems to have hit upon the solution I hit upon, which was: (I've deliberately left out most error checking since I want the main script body uncluttered)

And wouldn't you know it, I left out a piece. Here's a corrected script:

#!/usr/bin/perl
use strict;

open(STDIN, '<', shift) if @ARGV;
open(STDOUT, '>', shift) if @ARGV;

my $mline='';
my $prefix='';

while(<>) {
/^(\w+)\.[A-Z]$/ or die "Bad line: $_";
if ($prefix ne $1) {
$prefix = $1;
print $mline;
$mline = "$prefix.M\n";
}
if ($mline lt $_) {
print $mline;
$mline = '';
} elsif ($mline eq $_) {
$mline='';
}
print;
}
print $mline;
__END__



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise