in reply to Parsing answer for a 'yes'

You have confused Perl's logical OR operator || with the regex's alternation token, |. And why do you have the /g modifier in your regex?

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: I think I'm close...
by ropey (Hermit) on Mar 01, 2002 at 17:21 UTC
    Jeff is right, use the single |, this should do what you want, will die if the answer is not Y or Yes, otherwise just carries on. Just make sure you use warnings and strict
    print "Do you want to submit Job A? "; chomp (my $question = <STDIN>); die "Goodbye\n" unless $question=~ /(yes|y)/i; print "Are You Sure? "; chomp (my $question2= <STDIN>); die "Goodbye\n" unless $question2 =~ /(yes|y)/i; print "Everything good\n";
    Hope this helps ...
Re: Re: I think I'm close...
by ddrumguy (Acolyte) on Mar 01, 2002 at 17:36 UTC
    what does the g do anyway (i forget)? I think I must of swiped this from somewhere else (another piece of code) Thanks it is working now bob
      The /g is Perl's global match modifier. In this case, you're only looking for a single match, so you don't need it.

      I would also suggest taking the approach VSarkiss uses below and anchoring your regex:

      	if ($question =~ /^y/i) ...
      
      works great for all concerned, while this:
      	if ($question =~ /(yes|y)/i) ...
      
      not only matches, "yes" and "y", but also matches "maybe", "not necessarily", "no way", "definitely not", and "/me rolls eyes".

      -- grummerX

      The g matches globally(all occurances). In a list context, it returns the list of substrings matched by capturing parentheses(if no capturing parens, it returns a list of all matched strings).