|
Re: [QUIZ] Perl 'Easy' Quiz of the Week #2005-1: msg#00038lang.perl.qotw.discuss
My solution is very similar to Roger's. #!/usr/local/bin/perl -w if (@ARGV > 2) { die "usage: $0 [<input file> [<output file>]]\n"; } if (@ARGV == 2) { my $out = pop @ARGV; open STDOUT, ">$out" or die "Cannot open $out for writing.\n"; } my $last_prefix = ''; my $printed_m = 1; while (<>) { chomp; my($prefix, $suffix) = split /\./; if ($prefix ne $last_prefix) { if (not $printed_m) { print "$last_prefix.M\n"; } $last_prefix = $prefix; $printed_m = 0; } if ($suffix eq 'M') { $printed_m = 1; } if ($suffix gt 'M' and not $printed_m) { print "$last_prefix.M\n"; $printed_m = 1; } print "$_\n"; } if (not $printed_m) { print "$last_prefix.M\n"; } __END__ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [SPOILER] My Solutions to the Problem: 00038, Shlomi Fish |
|---|---|
| Next by Date: | Re: [QUIZ] Perl 'Easy' Quiz of the Week #2005-1: 00038, Brad Greenlee |
| Previous by Thread: | Re: [QUIZ] Perl 'Easy' Quiz of the Week #2005-1i: 00038, Roger Burton West |
| Next by Thread: | Re: [QUIZ] Perl 'Easy' Quiz of the Week #2005-1: 00038, Brad Greenlee |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |