logo       

Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1: msg#00045

lang.perl.qotw.discuss

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

On Mon, Jan 24, 2005 at 01:11:33PM -0500, Daniel Martin wrote:

That's a neat approach.

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

if ($mline eq $_) {
$mline = '';
}

Otherwise you print out an extra "mline" when one already exists.

> if ($mline lt $_) {

You could change that to

if ($mline and $mline lt $_) {

to save a lot of unnecessary printing of an empty string.

> print $mline;
> $mline = '';
> }
> print;
> }
> print $mline;
> __END__


Ronald



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

News | FAQ | advertise