CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: HELP: Edit Log



yaroba
Novice

Mar 29, 2013, 6:34 PM


Views: 1102
HELP

I need to write a program that counts words seperated by spaces, double spaces, commas and dots. I wrote it, but it does not work right. Can anyone help me? Here is the code.

open(FILE, "1z.txt") or die "Negaliu atidaryt: $!";
my ($words) = (0,0,0);
while (<FILE>) {
chomp;
$a=$words = split(/ {2,}/, $_);
$b=$words = split(/ /, $_);
$c=$words = split(/./, $_);
$d=$words = split(/,/, $_);
$sum= $a+$b+$c+$d
}
print("$a, $b, $c, $d\n");
print("words=$sum\n");


(This post was edited by yaroba on Mar 29, 2013, 6:34 PM)


Edit Log:
Post edited by yaroba (Novice) on Mar 29, 2013, 6:34 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives