On Monday, April 8, 2002, at 06:24  AM, David Gray wrote:

>> I believe it is as simple as:
>>
>> $count = () = $string =~ /,/g;
>
> I can't seem to get my brain around what's happening here... would
> someone be kind enough to explain?
>
>  -dave

$string =~ /,/g;

that finds all occurrences of comma in the variable, $string.

assigns the result in a list context - the anonymous list '()'.
by assigning this to a scalar, $count, we get a value that is the size of 
the list, which is the number of matches that the regex made.
that empty list thingy is confusing.
it is more comprehensible if you assign it to a named array:
$count = @arr = $string =~ /,/g;
the matches are in @arr which consists of the comma of the match.
then $count is the size of the array.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to