Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 contemplating the Monastery: (7)
As of 2014-10-22 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (117 votes), past polls