Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

map grep and sort

by coyocanid (Acolyte)
on May 24, 2013 at 17:49 UTC ( #1035181=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @caps = grep { $_ =~ /^[A-Z]/ } qw( This is for Edna );
    
  2. or download this
    my @caps = grep { /^[A-Z]/ } qw( This is for Edna );
    
  3. or download this
     my @vowel_caps = grep { /^[A-Z]/ } grep { /^[aAeEiIoOuU]/ } 
                                          qw( This is for Edna );
    
  4. or download this
      my @numbers = sort { $b <=> $a } ( 23,5,23,64,2);
      my @words = sort { $b cmp $a } 
    ...
                                          { name => "bar", order => 88 }, 
                                          { name => "baf", order => -12 },
                                          { name => "zoo", order=>88 } );
    
  5. or download this
    my @squares = map { $_ * $_ } ( 1,2,3,4,5,6 );
    my @even_squares = map { $_ * $_ } grep  { $_/2 == int($_/2) } 
    ...
          map { [ "zero", "one", "two", "three", "four", 
                      "five", "six", "seven", "eight", "nine" ]->[$_] } 
          grep { $_/2 == int( $_/2 ) } ( 1,2,3,4,5,8,9 );
    
  6. or download this
    my @doubled = map { $_, $_ } ( 1,3,4,5,6,6 );
    my @flattened = map { @$_ } ( [ 1,2,3], [ "A","B","C" ], [ $var1, $var
    +2, $var3 ] );
    my %squares_hash = map { $_ => $_ * $_ } ( 1,2,3,4,5,6 );
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1035181]
Approved by Paladin
Front-paged by MidLifeXis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-07-30 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (234 votes), past polls