Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: How to count substitutions on an array

by davido (Cardinal)
on Aug 14, 2016 at 02:42 UTC ( [id://1169733]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to count substitutions on an array
in thread How to count substitutions on an array

Thanks. You caught me!

Here are some idioms that could be preferable:

use strict; use warnings; my @data = qw(foozbar foozball zoobeezoobedo); my $acc = 0; do { my $count = s/o/*/g; $acc+=$count; } for @data; print "$acc\n"; # But the above really can just boil down to: my $count; $count += s/\*/o/g for @data; print "$count\n"; # List::Util's reduce is always fun. use List::Util 'reduce'; my $total = reduce {$a += $b =~ s/o/*/g} 0, @data; print "$total\n";

Hope this helps (and thanks again for catching the error).


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found