in reply to How to find which comes first: ' " ', '(', or ')'?
<Editor's Note>my ($first) = $string =~ /(["()])/;
From perlop:
If the `/g' option is not used, `m//' in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., (`$1', `$2', `$3'...).So, by parenthesizing the character class containing the characters you want to find, the regex will return that character when matched.Examples:
if ( ($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/) )
The parentheses around the left-hand-side variable (here,
$first) are required, to put the expression in list context.
In scalar context, a regex will only return true or false.
</Editor's Note>
|
---|
In Section
Seekers of Perl Wisdom