View Full Version : help with perl
99shassan
04-22-2008, 10:40 PM
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
4play
04-23-2008, 02:10 PM
$str = "place the string you want to count in here";
$count = $str =~ s/([a-z])/$1/gi;
print $count;
99shassan
04-24-2008, 01:18 PM
$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 :)
paleywiener
04-25-2008, 02:55 PM
$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//;"
Powered by vBulletin® Version 4.2.3 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.