Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: regular expressions

by si_lence (Deacon)
on Feb 01, 2005 at 18:14 UTC ( #426991=note: print w/replies, xml ) Need Help??


in reply to regular expressions

hi
Use a total counter outside your loop and print it out at
the end.
Something along the lines of:
use strict; use warnings; my $total; while(<DATA>) { my ($county, $year, $yr_tot) = split; $total += $yr_tot if $county =~ /26005/; } print "Total for county 26005: $total\n"; __END__ 26005 2004 1 26005 2004 2 26005 2004 3 26004 2004 1 26003 2004 1

si_lence
update: typo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://426991]
help
Chatterbox?
[shmem]: hmm...
[shmem]: Lady_Aleena: perl -MMP3::Tag -MFile::Find -le 'find(sub{if($File ::Find::name=~/\. mp3$/){$sum+=MP3:: Tag->new($_)-> interpolate("\%S ")} }, "Music"); print "total seconds: $sum"'

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-04-23 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.