Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: count multiple variables in a single array.

by AnomalousMonk (Bishop)
on Feb 26, 2020 at 21:36 UTC ( #11113460=note: print w/replies, xml ) Need Help??


in reply to count multiple variables in a single array.

As an example of what 1nickt suggested, maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my @files = qw( TUMI-1354839054_alt1 1.psd maur-1111.psd Sam-I-Am.gif maur-1110.psd ); ;; my %user_tag_title = qw(TUMI TUMI BW BW maur maurices); ;; my ($rx_user_search) = map qr{ $_ }xms, join ' | ', map quotemeta, reverse sort keys %user_tag_title ; print $rx_user_search, qq{\n}; ;; my %files_seen; FILE: for my $file (@files) { next FILE unless my ($user) = $file =~ m{ ($rx_user_search) }xms; push @{ $files_seen{$user} }, $file; } dd \%files_seen ;; USER: for my $user (sort keys %user_tag_title) { next USER unless exists $files_seen{$user}; ;; printf qq{%d $user_tag_title{$user} files \n%s \n\n}, scalar(@{ $files_seen{$user} }), join qq{\n}, @{ $files_seen{$user} }; } " (?msx-i: maur | TUMI | BW ) { TUMI => ["TUMI-1354839054_alt1"], maur => ["maur-1111.psd", "maur-1110.psd"], } 1 TUMI files TUMI-1354839054_alt1 2 maurices files maur-1111.psd maur-1110.psd
For a discussion of how  $rx_user_search is built, see haukex's Building Regex Alternations Dynamically.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2020-06-01 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (5 votes). Check out past polls.

    Notices?