In article <9f2a27ae-87e8-4dfb-a29e->,
C.DeRykus <> wrote:
>On Dec 27, 2:04*am, David Filmer <davidfil...@davidfilmer.com> wrote:
>> How can I match continuous alphanumeric strings which contain more
>> than one underscore?
>
>Maybe,
>
>print '>1' if (()= /\G [[:alnum:]]+ _/gx) > 1;
For anyone else who is wondering about the use of ()=, please see "man
perldata".
List assignment in scalar context returns the number of elements
pro- duced by the expression on the right side of the assignment:
$x = (($foo,$bar) = (3,2,1)); # set $x to 3, not 2
$x = (($foo,$bar) = f()); # set $x to f()'s return count
This is handy when you want to do a list assignment in a Boolean
context, because most list functions return a null list when
finished, which when assigned produces a 0, which is interpreted
as FALSE.
It's also the source of a useful idiom for executing a function or
performing an operation in list context and then counting the
number of return values, by assigning to an empty list and then
using that assignment in scalar context. For example, this code:
$count = () = $string =~ /\d+/g;
will place into $count the number of digit groups found in
$string. This happens because the pattern match is in list
context (since it is being assigned to the empty list), and will
therefore return a list of all matching parts of the string. The
list assignment in scalar context will translate that into the
number of elements (here, the number of times the pattern matched)
and assign that to $count. Note that simply using
$count = $string =~ /\d+/g;
would not have worked, since a pattern match in scalar context
will only return true or false, rather than a count of matches.
--
Tim McDaniel,