"Raghupathy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Rob and David,
>
>   Thanks very much! That's exactly what I am looking
> for and sorry for the misleading subject on the email.
>
>
> Rob: Could you please explain why you need 2 questions
> marks on line#7 instead of just one minimal quantifier
> needed  (I hope I am using the right words this time
> !!!).
>
> Thanks,
> Ramesh
>
> 1 while ( $code =~ m{
> 2    \#(ifn?def) \s+ def \s* \n
> 3    (.*?) \s+
> 4    (?:
> 5    \#else \s+ def \s* \n
> 6    (.*?) \s+
> 7    )??
> 8    \#endif \s+ def \s* \n
> 9  }isxg ) {
>
> 10  my ($def, $undef) = $1 eq 'ifdef' ? ($2, $3
> 11  || '') : ($3 || '', $2);
>
> 12  printf "  Defined: %s\n", $def;
> 13  printf "Undefined: %s\n", $undef;
> 14  print "\n";
> }

Sure. The first question mark is a quantifier: the same as
{0,1}, meaning 'match one repetition if possible, otherwise
none'. The second is a non-greedy modifier, turning it into
'match no repetitions if possible, otherwise one'.

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to