in reply to Counting within numerous files?

Your problem as you state it is not how to count the occurances of a character. It is how to cycle through all the files in your list and keep track of that accumulating count.

Here's a bit of sample code that should help:

use strict; # these are sample files from my test directory my @files = qw(testhere.pl closure.pl hello.pl); my $semi_count; foreach my $file (@files) { open FILE, $file or die "Can't open $file: $!\n"; $semi_count += tr /;// for <FILE>; close FILE; } print $semi_count;

Replies are listed 'Best First'.
Re: Re: Counting within numerous files?
by davorg (Chancellor) on Jul 19, 2001 at 19:23 UTC

    Another alternative would be the little-used trick of assigning to @ARGV. You can then read each line of all of the files in turn using the diamond operator, <>.

    @ARGV = qw(testhere.pl closure.pl hello.pl); my $semi_count; $semi_count += tr/;// while <>;

    Update: Less patronising, more informative.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>