in reply to Re: I think I'm close...
in thread Parsing answer for a 'yes'

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

Replies are listed 'Best First'.
Re: Re: Re: I think I'm close...
by grummerX (Pilgrim) on Mar 01, 2002 at 21:08 UTC
    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

Re: Re: Re: I think I'm close...
by dmouille (Novice) on Mar 01, 2002 at 21:16 UTC
    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).