in reply to Re: Perl Help
in thread Perl Help

I'm trying to count the instances of certain characters within a text file. Here is what I have written so far. I'm having a problem with the brackets. Its picking them up as character classes. Help.
open (READFILE, "<readme.txt") || die "Couldn't open file: $!"; $buffer = ""; while(<READFILE>) { $commas++ while ($_ =~ m/,/g); $fullstops++ while ($_ =~ m/\./g); $openbracket++ while ($_ =~ m/[/g); $closedbracket++ while ($_ =~ m/]/g); $hypehns++ while ($_ =~ m/-/g); }

Replies are listed 'Best First'.
Re^3: Perl Help
by moritz (Cardinal) on Jan 22, 2008 at 11:58 UTC
      I still can't get it to pick up brackets. Please help? Is there an ASCII equivelent I can search for.
      open (READFILE, "<readme.txt") || die "Couldn't open file: $!"; $buffer = ""; while(<READFILE>) { #print $_; $commas++ while ($_ =~ m/,/g); $fullstops++ while ($_ =~ m/\./g); $openbracket++ while ($_ =~ m/\[/g); $closedbracket++ while ($_ =~ m/\]/g); $hyphens++ while ($_ =~ m/-/g); } print ("$commas commas\n"); print ("$fullstops full stops\n"); print ("$openbracket open brackets\n"); print ("$closedbracket closed brackets\n"); print ("$hyphens hyphens\n");