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

Carl Gherardi C.Gherardi at curtin.edu.au
Mon Nov 18 11:06:13 WST 2002


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

> 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



More information about the plug mailing list