Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Mapping list to hash is dropping list items

by jwkrahn (Abbot)
on Mar 12, 2022 at 23:27 UTC ( [id://11142060]=note: print w/replies, xml ) Need Help??


in reply to Mapping list to hash is dropping list items

This may work better (UNTESTED):

#!/usr/bin/perl use strict; use warnings; my @allTags; { local @ARGV = <[0-9][0-9][0-9][0-9].txt>; my %uniqueTags; while ( my $line = <> ) { next unless $line =~ s/^tags\s+//; $line =~ s/\s+\z//; $uniqueTags{ $_ } = 1 for split /\s+,\s+/, $line; } @allTags = keys %uniqueTags; } print "@allTags\n";

Replies are listed 'Best First'.
Re^2: Mapping list to hash is dropping list items
by almsdealer (Acolyte) on Mar 16, 2022 at 16:28 UTC
    If I understand correctly, <> will read from @ARGV unless it is empty in which case it will read from STDIN?

    Also, why did you wrap everything between my @alTags and print in a block?

      When used like this the diamond operator is actually glob which generates a list of filenames; those filenames are used to populate @ARGV and (yes) then the plain <> readline version will implicitly read from those files. The block was (my guess) probably intended to scope the local change to @ARGV to just that section of code.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found