in reply to Re: perl command line prompts
in thread perl command line prompts

The program doesn't stall anymore after a command line prompt, but it replaces the matched strings even if you enter a "n".

if ($answer == "y") { print $MOD $change; } else { print $MOD $_; }
No matter what character is entered at the command prompt, the program replaces all of the matches. How can I fix this? Thanks.

Replies are listed 'Best First'.
Re^3: perl command line prompts
by holli (Abbot) on May 16, 2005 at 20:23 UTC
    two ways:
    if ($answer eq "y") { #this is a string comparison. == is for numbers +only
    or (maybe better)
    if ($answer =~ /^y/) {
    The latter will also work if the user types "yes", "yup", etc.


    holli, /regexed monk/
      and perhaps even:
      if ($answer =~ /^y/i) {
      To work with "Yup", "Yes", "yay" and "yak"
Re^3: perl command line prompts
by tlm (Prior) on May 16, 2005 at 21:17 UTC

    When reading your original post I missed the bug that holli's and Transient's replies fix. You must have seen this advice a trillion times: always run with strict and warnings. If you had, perl would have told you what the problem was.

    the lowliest monk

      Thanks to everyone for your help.