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

2023-06-16 Thread Freek de Kruijf
Op donderdag 15 juni 2023 22:31:31 CEST schreef Claude Brown:
> Is there any prior mention of "$normalise" in the script?

Only now I see the first mentioning of $normalize as:

$normalize = {}

The naming of it is quite confusing to me. More logically would have been 
"present".

Now I understand that it is a test to assure certain lines in the input file 
should not be present more than once.

> Assuming there isn't, most likely "$normalise->{$1}" is building out a
> hash-table with "$1" as the key and a value of 1 at each entry.  
> $normalise will be a reference to that hash.
> 
> To check if this is correct, do this sometime after this code:
> 
> use Data::Dumper;
> print Dumper($normalise);

Thanks a lot.

-- 

fr.gr.

Freek de Kruijf




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




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

2023-06-15 Thread Kang-min Liu


Freek de Kruijf  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

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




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

2023-06-15 Thread Andy Bach
 } elsif( /^(\#?\s*(?:pickup|qmgr)\s+)(?:fifo|unix)(\s+.*)/ ) {
  if( defined $normalize->{$1} ) { next; } else { $normalize->{$1} = 1;
}

if the string starting at the beginning of the line matches, $1 will
contain "zero or one #, zero or more whitespaces, either the word "pickup"
or "qmgr", one or more whitespace" - it's then being used as the kev value
in the hash referenced by $normalize - if that entry already has a true
value (probably a 1) don't do anything, otherwise, assign that key a 1 .
 Note, to fully match, that string has to be followed by either "fifo" or
"unix" and 1 or more whitespaces.  Everything (including those last
whitespaces) will end up $2.

I'm a tad puzzled as to what the purpose could be, there certainly are
easier ways to do this.  The "use " is including the module
.pm in the code, so it's subs/methods etc can be used by the
program.

On Thu, Jun 15, 2023 at 2:29 PM Freek de Kruijf 
wrote:

> 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.
>
> As far as can see the tested line in $_, from a file, is all ASCII with
> lower
> case characters. At the begin of the perl program the is no "use
> ".
>
> --
>
> fr.gr.
>
> Freek de Kruijf
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk