Ok after reading some of the suggestions here I decided to update the uselessmaster I would have prefered to post this in Seekers of Perl Wisdom but I decided instead that it would problably be a better idea just to edit my original post to include the second draft rather then clutter things up with a additional post, so heres the second version of the useless master.#!/usr/bin/perl -w #This Program will check to see on how many lines a word #or word fragment occurs print "Welcome to Uselessmaster 4000\n"; $op="S"; #Sets a Value to op so that there is no message about +it being uninitialized until ($op =~/Q/i) { print "Would you like to (S)earch a file or (Q)uit?\n"; $op=<STDIN>; if ($op =~/Q/i) { print "Just hit enter to shuffle though all prompts\n"; } print "enter the word you would like to check for\n"; chomp ($word=<STDIN>); print "enter the full pathname of the file you would like to search\n" +; $file=<STDIN>; open FILE, "<$file" or die "Sorry no luck opening file"; $totline=0; $occ=0; for $line (<FILE>) { $totline=$totline+1; if ($line =~/$word/i) {$occ=$occ+1;}; }; print "Of ",$totline," lines the word ",$word," occured on ",$occ," li +nes\n"; };
Thank you all for the suggestions and I hope that the second version is a improvement over the first.#!/usr/bin/perl -w use strict; #This Program will check to see on how many lines a word or word fragm +ent occurs print "Welcome to Uselessmaster 4000\n"; my($totline,$op,$word,$file,$occ,$line); $op="S"; #Sets a Value to op so that there is no message about +it being uninitialized until ($op =~/Q/i) { print "enter the word you would like to check for\n"; chomp ($word=<STDIN>); print "enter the full pathname of the file you would like to search\n" +; $file=<STDIN>; open FILE, "<$file" or die "Sorry no luck opening file $!"; $totline=0; $occ=0; for $line (<FILE>) { $totline++; if ($line =~/$word/i) {$occ++;}; }; print "Of ",$totline," lines the word ",$word," occured on ",$occ," li +nes\n"; print "which is is ",$occ/$totline*100,"% of the lines\n\n"; print "Would you like to (S)earch another file or (Q)uit?\n"; $op=<STDIN>; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The Useless Master 4000
by John M. Dlugosz (Monsignor) on Jul 04, 2001 at 01:41 UTC | |
|
Re: The Useless Master 4000
by BrentDax (Hermit) on Jul 06, 2001 at 06:53 UTC |