help with perl
(Click here to view the original thread with full colors/images)Posted by: 99shassan
Hi guys, I've loaded a file, and have removed the \n using chomp. however, when I try using length($file), it counts the whitespaces along with the characters. How do I just count the characters, anything but the whitespaces?
thanks
Posted by: 4play
$str = "place the string you want to count in here";
$count = $str =~ s/([a-z])/$1/gi;
print $count;
Posted by: 99shassan
$str = "place the string you want to count in here";
$count = $str =~ s/([a-z])/$1/gi;
print $count;
Hi, that will just count the lowercase characters right? what about capital letters? would it be something along the lines as [a-z]||[A-Z]? also, what is the $1 for?
done it thanks for your help :)
Posted by: paleywiener
$count = tr/a-zA-Z//;
perl -e "$_= 'blah blDh'; $count = tr/a-zA-Z//; print $count;"
perldoc perlop
or perl -e "$_= 'blah blDh'; print $count = tr/a-zA-Z//;"
