Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Remove letters from variables used in math operation?

by AnomalousMonk (Abbot)
on Dec 08, 2012 at 21:22 UTC ( #1007930=note: print w/ replies, xml ) Need Help??


in reply to Remove letters from variables used in math operation?

Another peasibility:

>perl -wMstrict -le "my $s = '86f,934e,92,102i,14,19,222,'; ;; my ($a,$b,$c,$d,$e,$f,$g) = split m{ [[:alpha:]]* , }xms, $s; my $sum = ($a+$b+$c+$d+$e+$f+$g); ;; print $sum; " 1469

Update: Or even:

>perl -wMstrict -le "use List::Util qw(sum); ;; my $s = '86f,934e,92,102i,14,19,222,'; ;; my $sum = sum split m{ [[:alpha:]]* , }xms, $s; ;; print $sum; " 1469

Also (tested):  my $sum = sum $s =~ m{ \d+ }xmsg;


Comment on Re: Remove letters from variables used in math operation?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-07-28 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls