Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Schwartzian Transform as a module?

by Sweeper (Pilgrim)
on Oct 01, 2002 at 05:38 UTC ( #201927=note: print w/replies, xml ) Need Help??


in reply to Schwartzian Transform as a module?

Take this example from the Cookbook (page 120)
print map { $_->[0] }
      sort {
          $a->[1] <=> $b->[1]
                   ||
          $a->[2] <=> $b->[2]
                   ||
          $a->[3] cmp $b->[3]
      }
      map { [ $_, (split /:/)[3, 2, 0] ] }
      qx(cat /etc/passwd);
How do you modularize a multi-criterion sort? Of course, it can be done, but the resulting module invocation would be more cumbersome and less readable than an inline Schwartzian transform.

Replies are listed 'Best First'.
Re: Re: Schwartzian Transform as a module?
by I0 (Priest) on Oct 02, 2002 at 06:18 UTC
    sub ST(&@){ my $metric=shift; map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {[$_,&{$metric}]} @_ } print ST{sprintf"%9d%9d%s",(split/:/)[3,2,0]} qx(cat /etc/passwd);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://201927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2020-10-21 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (212 votes). Check out past polls.

    Notices?