distro has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm beginning in perl and I'm having some trouble with a program. I need this program to be able to find a file that a user puts in (STDIN, I know) and then find the amount of times a word that they also choose in the file they have chosen... This is what I have so far, sorry if it's completely wrong.
I know it's a bit scattered but I've just been fiddling with it for hours trying to get it to work.
#!/usr/bin/perl -w use strict; print "Please enter the name of the file to search:"; while (<>){ print; } print "Enter a word to search for:"; chomp( my $input = <STDIN>; my $ctr=0; foreach($filename){ if (/\b$input\b/){ $ctr++; } } print "Frequency: $ctr\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: find the number of words that a user has chosen for an input file that a user has also chosen
by tybalt89 (Monsignor) on Nov 16, 2016 at 22:27 UTC | |
|
Re: find the number of words that a user has chosen for an input file that a user has also chosen
by GrandFather (Saint) on Nov 16, 2016 at 22:52 UTC | |
by distro (Initiate) on Nov 16, 2016 at 23:07 UTC | |
by GrandFather (Saint) on Nov 17, 2016 at 00:22 UTC | |
|
Re: find the number of words that a user has chosen for an input file that a user has also chosen
by 1nickt (Canon) on Nov 16, 2016 at 22:29 UTC | |
by distro (Initiate) on Nov 16, 2016 at 22:31 UTC |