tye is correct, however, his solution leaves a touch to be desired. Simply move the %msgs has to the top of the file. And I would recommend taking SteveAZ98's method of initializing the hash. Using => is a lot cleaner than the comma separated key/value pairs. Much more obvious which messages goes with which key, particularly if you decide to add to the list.

You could also simplify in a few places. Where you have
if ($method ne "GET") { if ($method ne "POST") { msg(400); } }
use instead
if ($method ne "GET" && $method ne "POST") { msg(400); }
Note that you probably want a return or and exit at this point, otherwise, you're going to continue executing code, after you've kicked an error message out. This is usually not what you want to do.

You can also simplify your file reading with this:
open(FILE1, $ARGV[0]); @lines = <FILE1>;
And, of course, as a responsible programmer, you'll be wanting to close the file when you're done with it. <G>

--Chris

e-mail jcwren

In reply to (jcwren) Re: calling a sub from an if statement by jcwren
in thread calling a sub from an if statement by cburns

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.