in reply to empty hits with regex
Here's a couple of other solutions:
my @hits = grep defined, m/(?:c(a)|k(t))/g;
my @hits; while ( m/(?:c(a)|k(t))/g ) { push @hits, defined $1 ? $1 : $2; }
The last one is extensible too:
my @hits; while ( m/(?:c(a)|k(t)|k(k))/g ) { push @hits, defined $1 ? $1 : defined $2 ? $2 : $3 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: empty hits with regex
by JavaFan (Canon) on Oct 02, 2008 at 20:38 UTC | |
by Tanktalus (Canon) on Oct 02, 2008 at 22:52 UTC |