Forsaken has asked for the wisdom of the Perl Monks concerning the following question:
the results will be stored in @matches all nice and tidy. however, what i'm a bit curious about is how to approach the extraction of a single element without having the result stored in an array. When using a similar extraction in scalar context like this:my @matches = ($text =~ /(stufftoextract)\w(morestufftoextract)/);
$match will be 1 to indicate a succesful match was made. Of course there is a relatively simple method to actually get to the result as follows:my $match = $text =~ /(stufftoextract)/;
What I'm wondering about now is whether there's other ways to get to the same result in a single line of code, so first matching and simply assigning the value of $1 to $match doesn't count ;-)my $match = ($text =~ /(stufftoextract)/)[0];
Remember rule one...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One-liner regex extraction
by ikegami (Patriarch) on May 18, 2005 at 19:00 UTC | |
by Forsaken (Friar) on May 18, 2005 at 19:03 UTC | |
by holli (Abbot) on May 18, 2005 at 19:25 UTC | |
by Forsaken (Friar) on May 18, 2005 at 19:56 UTC |