|
Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1: msg#00053lang.perl.qotw.discuss
Here's mine, substantially similar to Brad Greenlee's. #!/usr/bin/perl use warnings; use strict; my ($input, $output) = @ARGV; my ($inputfh, $outputfh); open $inputfh, "<$input" or die "Can't open $input: $!"; open $outputfh, ">$output" or die "Can't open $output: $!"; my %suffix; my $currentpref = ''; while (<$inputfh>) { chomp; my ($pref, $suf) = (/^(\w+)\.([A-Z])$/); if ($currentpref and $pref ne $currentpref) { output_pref($currentpref); $currentpref = $pref; } $currentpref ||= $pref; $suffix{$suf}++; } output_pref($currentpref) if $currentpref; sub output_pref { my $currentpref = shift; $suffix{M}++; print $outputfh "$currentpref.$_\n" for sort keys %suffix; %suffix = (); } |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Sample solutions and discussion - Perl 'Medium' Quiz of the Week 2005-1: 00053, Shlomi Fish |
|---|---|
| Next by Date: | Re: [QUIZ] Perl 'Easy' Quiz of the Week #2005-1 - Timing: 00053, David Jones |
| Previous by Thread: | Re: [SPOILER] Perl 'Easy' Quiz of the Week #2005-1i: 00053, John Macdonald |
| Next by Thread: | [SPOILER] Perl 'Easy' Quiz of the Week #2005-1: 00053, Luke Triantafyllidis |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |