[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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