[plug] [Perl] sorting arrays based on scalar value - Golf any one?

Matthew Robinson matt at zensunni.org
Mon Nov 18 16:28:34 WST 2002



Carl Gherardi wrote:
> Hmm.. Doesn't work actually, been a while since I use that arg to perl
> 
> Lets take out the need of a sub
> 
> ./program.pl infile
> 
> #!/usr/bin/perl -p             03
> open O,">@_~";                 14
> print O sort{$b<=>$a}<>        23
>                              -----
>                                40
> 
> Should produce sorted output file infile~ and stdout.
> 
> Carl
> 
> Disclaimer: untested - no box with perl handy

I've just tested it for you and it still doesn't work ;)  I think the 
fact that -p is wrapping it all in a while(<>) { ... } loop and then you 
are sucking the contents of <> into the sort is confusing perl and 
causing it to stop dead waiting for more input.


Matt


> 
>>From: Matthew Robinson
>>
>>
>>Carl Gherardi wrote:
>>
>>>Borrowing from Tony
>>>
>>>Assume perl called with -p option
>>>
>>>perl -p                        03
>>>sub resort{                    11
>>>open O,">@_[1]";               16
>>>print O sort{$b<=>$a}<>        23
>>>}
>>>                             -----
>>>                               53
>>>
>>
>>This doesn't work for me!  Can you explain how I should be 
>>calling it to 
>>get the same results as the previous entries.
>>
>>Matt
> 
> 
> .
> 

-- 
print map{s&^(.)&\U\1&&&$_}split$,=$",(`$^Xdoc$,-qj`=~m&"(.*)"&)[0].$/



More information about the plug mailing list