Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: What is the meaning of $normalize->{$1}

5 views
Skip to first unread message

Kang-min Liu

unread,
Jun 15, 2023, 6:30:06 PM6/15/23
to begi...@perl.org

Freek de Kruijf <f.de....@gmail.com> writes:

> Hi,
>
> I am trying to understand fully a perl program with the following lines:
>
> } elsif( /^(\#?\s*(?:pickup|qmgr)\s+)(?:fifo|unix)(\s+.*)/ ) {
> if( defined $normalize->{$1} ) { next; } else { $normalize->{$1} = 1; }
> I do understand the first line, but I can not find what the second line is
> about.

$1 contains the content of the first capturing group in the matching
regexp. in this case, "#pickup", "#qmgr", "pickup", "qmgr"... etc.

$normalize->{$1} means: getting the corresponding value of $1 from the
HashRef $normalize.

$normalize->{$1} = 1 means: setting the corresponding value of $1 to 1.

`next` is a keyword for skipping the rest of loop, so it would seem to
me that these 2 lines is inside of a loop. I'm guessing $_ is the
iterator of the loop. Assuming that's the case, it appears to me
$normalize is used to keep track the occurance of the captured
words. Not how may times they occur, just if they occur or not.

--
Cheers,
Kang-min Liu
0 new messages