in reply to Switch statement?

The problem is most likely because you have one too many opening parenthesis somewhere, and Switch.pm only knows that when it has reached the end of the file.

But you can write your program much much easier and shorter and thus avoid the counting of parentheses by using a hash, which maps each character to the number it occurs:

#!/usr/bin/perl -w use strict; my $infile = $ARGV[0]; open INPUT, "<", $infile or die "Couldn't open '$infile' : $!"; my $input = do { local $/; <INPUT> }; my %histogram; for my $char (split //, $input) { $histogram{$char}++; }; for (keys %histogram) { print "$_ occurred $histogram{$_} times.\n"; };

Replies are listed 'Best First'.
Re^2: Switch statement?
by The Mad Hatter (Priest) on Jul 18, 2004 at 20:37 UTC
    Corion is right; there are two places where you actually have one too many open parens:
    $tmp = uc(substr(($indata,$i,1)); # a bc cb ... no a switch (($tmp) { # ab b ... no a
      for (($i=0; $i<$len; $i++) { # ab b ... no a