Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Remove letters from variables used in math operation?

by AnomalousMonk (Monsignor)
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: (19)
As of 2014-04-23 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls