logo       

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

lang.perl.qotw.discuss

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

Sorry, my bad. Upon second reading it's just fine.

-b

Shlomi Fish said:
> On Monday 24 January 2005 19:26, Brad Greenlee wrote:
>> The problem stated that the output should be sorted. That wouldn't be
>> the
>> case with this solution.
>>
>
> Why not? Seems fine to me, and it passes all the tests in my test suite.
> Can
> you give an example where it doesn't produce the expected output?
>
> Regards,
>
> Shlomi Fish
>
>> -b
>>
>> Ronald J Kimball said:
>> > 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__
>
> --
>
> ---------------------------------------------------------------------
> Shlomi Fish shlomif-ik1l9ssToec+JF/nGntIXQ@xxxxxxxxxxxxxxxx
> Homepage: http://www.shlomifish.org/
>
> Knuth is not God! It took him two days to build the Roman Empire.
>




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

News | FAQ | advertise