UPDATE. Thanks everyone! Most helpful.#! c:\perl\bin print("Enter filename to open (text only):\n\n"); $in=<STDIN>; chomp $in; if ($in !~ /\.txt$/i) { $in.=".txt"; } open ($in, "$in") or die("$in could not be opened:$!\n"); print("Enter string to replace \"and\" with:\n\n"); $word=<STDIN>; chomp $word; print("Enter filename to SAVE text file as:\n\n"); $out=<STDIN>; chomp $out; if ($out !~ /\.txt$/i) { $out.=".txt"; } open($out, ">$out") or die $!; print ("\n\n\n"); $count=0; while (<$in>) { s/\band\b/$word/ig; while (/\band\b/ig) { ++$count; } print($out "$_\n"); } print "there were $count instances of \"and\" in $in"; close $out; close $in;
In reply to Counting instances of words by scarymonster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |