Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-17 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls