Folks, Just a quick question, in below script if user input is "Enter key" then I can't return to main menu. It defaults to condition 3 (I don't understand why)?
Can you please suggest me how can I detect an Enter key. I was trying to use Switch fuction but its not working in PERL V 5.8.4. Appreciate your help.
#!/usr/bin/perl local ($bak_id)=shift; local ($acc_bal)=shift; $bak_id=<STDIN>; $acc_bal=<STDIN>; chomp ($bak_id); print "bak_id = $bak_id\n"; print "acc_bal = $acc_bal\n"; if (($acc_bal < 1.0 ) && ($bak_id eq "BOTH")) { print "condition 1\n"; } elsif (($acc_bal > 1.0 )&&($bak_id eq "BOTH")){ print "condition 2\n"; } elsif (($acc_bal < 1.0 ) && ($bak_id eq ("Cust1")||("Cust2"))) { print "condition 3\n"; } elsif (($acc_bal > 1.0 ) && ($bak_id eq ("Cust1"||"Cust2"))) { print "condition 4\n"; local ($choice); $choice=<STDIN>; if ($choice="YES") { print "condition 4.1\n" } elsif ($choice!="YES") { print "condition 4.2\n"; } } elsif (($bak_id eq "\n") || ($acc_bal eq "\n")) { print "return to MM\n"; } else { print ("Returning to Main Menu\n"); }

In reply to Detecting a Null or Enter key by John007

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.