I need help with my program, I had everything working but then when I went back to try it out my second if statement was failing every time.
Anyone know what to do instead?
If statement
print "Enter a word to search for:"; chomp (my $word = <STDIN> ); if (not -e $word){ print "No such word found.\n"; exit; }
PROGRAM
#!/usr/bin/perl -w use strict; print "Welcome to the word frequency calculator.\n"; print "This program prompts the user for a file to open, \n"; print "then it prompts for a word to search for in that file,\n"; print "finally the frequency of the word is displayed.\n"; print " \n"; print "Please enter the name of the file to search:"; chomp (my $filename = <STDIN> ); if (not -e $filename){ print "No such file exists. Exiting program. Please try again. +\n"; exit; } print "Enter a word to search for:"; chomp (my $word = <STDIN> ); if (not -e $word){ print "No such word found.\n"; exit; } print "Frequency of word: " . grep $word eq $_, split /\W+/i, do { local (@ARGV, $/)= $filename; <> }; exit;
Thanks!
In reply to Need help with an if statement by distro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |