Hi,

try this approach by completing this program,

the ... is the part you write, refer to perlintro and Basic debugging checklist as your study notes.

When you're finished or when you get stuck , post what you have , ask a question

#!/usr/bin/perl -- use strict; use warnings; our %messages = ( welcome => " Welcome... ", promptfile => "Please enter the name of the file to search:", promptword => "Enter a word to search for:", byenofile => "No such file exists. Exiting program. Please try aga +in.\n", byenoword => "No such word found.\n", wordfrequency => "...", ); ## debugging WordFrequency exit WordFrequency( \"this is in memory test file with test words", "t +est" ); my $file = Prompt( $messages{welcome}.$messages{promptfile} ); my $word = Prompt( $messages{promptword} ); WordFrequency( $file, $word ); exit; sub WordFrequency { my( $file , $word ) = @_; open my($fh), '<', $file or die $messages{byenofile}; my $freq = 0; ...; if( $freq ){ print $messages{wordfrequency}, $freq, "\n"; } else { print $messages{byenoword}; } return $freq; } sub Prompt { ... }

In reply to Re: Need help with an if statement by beech
in thread Need help with an if statement by distro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.