KStowe has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I have this:
use strict; my @files = qw(FILES); 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;
I now need it to get a running total of ";" occurances while skipping the "; End" occurances within the files. Can I continue to use the tr/// operator or should I switch to the sub? Thanks so much.

Replies are listed 'Best First'.
(tye)Re: Exempting through search
by tye (Sage) on Jul 26, 2001 at 01:31 UTC
    $semi_count += tr /;// - (()=/;\s*End/gi) for <FILE>;
            - tye (but my friends call me "Tye")
      Thank you sir, worked like a charm. You are a gentlemen and a scholar! Much appreciated. Thats why I like coming here, get help with your problems, and learn a ton in the process. thanks again!
Re: Exempting through search
by bikeNomad (Priest) on Jul 26, 2001 at 01:05 UTC
    You could use the m// operator:

    $semi_count += () = m{;(?!\s*End)}g;

    update: added the \s* (didn't see the space initially)