[Omaha.pm] Tighter/cleaner way to do this? map { grep {} } ?

Jay Hannah jay at jays.net
Thu Feb 5 10:28:45 PST 2009


Ooo... cool. 


Old code:

my @b;
foreach (@a) {
   if (/(gold\w+)/) {
      push @b, $1;
   }
}


New code:

my @b = map { /(gold\w+)/ } @a;


map gets the matches only ($1), not the entire original string.  :)

j



More information about the Omaha-pm mailing list