Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

graff's scratchpad

by graff (Chancellor)
on Jun 02, 2004 at 01:42 UTC ( #358966=scratchpad: print w/replies, xml ) Need Help??

@sorted = map { s/^\S+ // } sort map { my ( $x ) = ( /^_(\S+)/ ) ? ( $1 ) : ( /(\S+)$/ ); "$x $_" } @unsorted;
Explanation (going upwards from the bottom, which is how it works):
  1. The first map block (the one on the bottom) creates a lexically scoped variable $x, and assigns a single non-whitespace token (string) to it. The value of $x depends on whether $_ (the current string from @unprocessed that map is handling) begins with "_". If it does, $x gets the first token of the line (minus the "_"), otherwise, it gets the last token.
  2. Each iteration of the first map outputs the string "$x $_"
  3. The sort works in the normal way, working on the modified list of strings
  4. The second map block (at the top) reprocesses the sorted list of strings, by undoing the work of the first one, by removing the initial token from each item.

An adaptation of a code snippet from LadyAleena's scratchpad:

elsif ($type =~ /name/) { for ( $c, $d ) { my $x = ( /^_(.*)/ ) ? $1 : substr( $_, rindex( $_, ' ' )) +; $_ = "$x $_"; } return $c cmp $d; }
Log In?

What's my password?
Create A New User
[Eily]: can't the nodelet be moved though? Maybe you could put one that doesn't change first ("Sections" or "Find Nodes" for example)
[Eily]: "Other Users" seems like a poor choice :P
[Eily]: nope, Nodelet Settings doesn't let you move the XP Nodelet, CSS might
[marinersk]: That would mitigate the distraction/jangle issue, but then the information wouldn't be easy to find when it is populated. Plus, I don't currently see a way to move it, but I'm not done poking around on that point yet.
[marinersk]: Ah, you beat me to it.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-05-29 14:09 GMT
Find Nodes?
    Voting Booth?