Keep It Simple, Stupid PerlMonks

### map grep and sort

by coyocanid (Sexton)
 on May 24, 2013 at 17:49 UTC Need Help??

```my @caps = grep { \$_ =~ /^[A-Z]/ } qw( This is for Edna );
```
```my @caps = grep { /^[A-Z]/ } qw( This is for Edna );
```
``` my @vowel_caps = grep { /^[A-Z]/ } grep { /^[aAeEiIoOuU]/ }
qw( This is for Edna );
```
```  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 } );
```
```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 );
```
```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 );
```

Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1035181]
Front-paged by MidLifeXis
help
Chatterbox?
 usemodperl can see the monastery has become a rehab for children of the serpent :-) usemodperl can't figure out how to get metacpan.org to comply with HTTP standards :-( HTTPS only!? Breaks older HTTP::Tiny...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-06-24 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (126 votes). Check out past polls.

Notices?