[Chicago-talk] Could someone explain this

Joel Limardo joel.limardo at forwardphase.com
Thu Jun 28 10:56:09 PDT 2018


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

When curious to know what long, somewhat tricky Perl lines of code are
doing you can just split them up into mulfiple instructions and then use
the debugger to figure out what is being passed around.

On Jun 28, 2018 12:47 PM, "Jim Jacobus" <JJacobus at ponyx.com> wrote:

> Hi,
> I'm embarrassed to ask this, but I'd like to understand this piece of code.
>
> I want to find out how many times a certain substring appears in the
> string ($block). $block is a very long string that is part of an XML file.
> I found this when rooting around for an example:
>
> my $count = () = ( $block =~ m/\<category\>/g);
>
> It does work. $count gives me the number of times the substring appears in
> $block.
> However, I don't undstand how this works. What is "= () =" mean.
>
> Jim
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20180628/88bdeca0/attachment-0001.html>


More information about the Chicago-talk mailing list