[Chicago-talk] Could someone explain this

Randal L. Schwartz merlyn at stonehenge.com
Sun Jul 1 19:27:10 PDT 2018


>>>>> "Joel" == Joel Limardo <joel.limardo at forwardphase.com> writes:

Joel> The match with the /g operator says find all so and that is in
Joel> parentheses so my guess is that produces a list containing all of
Joel> the matches. That gets assigned to an anonymous array which in
Joel> turn is being assigned to a scalar which, as you should know from
Joel> rudimentary Perl lessons, results in the number of elements in the
Joel> array to be returned.

Not quite right.  There's no assignment to an anonymous array.  It's
just that "list assignment in scalar context" provides a list context to
the right side, and then counts the items it *would* have put into
something on the left side, and returns that as a scalar.

It's similar to how:

  if (my ($x, $y) = m{(.*)/(.*)}) { ... }

evaluates that list assignment in a scalar (boolean) context, which
returns 0 if it doesn't match, or 2 if it does.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/Dart consulting, Technical writing, Comedy, etc. etc.
Still trying to think of something clever for the fourth line of this .sig


More information about the Chicago-talk mailing list