Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1
Ronald J Kimball <[email protected]> Mon, 24 Jan 2005 13:22:42 -0500
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
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