--- Michael Alipio <[EMAIL PROTECTED]> wrote: > I see... so in substitutions, all patterns in the left side are those that > have to be substituted, regardless of which is enclosed in parenthesis.
Well, with a lot of hand-waving, then yes, that's basically correct. (There are exceptions, but those are generally for advanced features you're unlikely to encounter right now and that would be a distraction to the current topic). > However in a plain regexp look ups, only those inside the parenthesis are > being matched... No, not correct. The regular expression is what's being matched. Period. The capturing parentheses merely capture some of all of the regular expression into a 'dollar digit' variable ($1, $2, and so on). So for this: $var =~ s/foo(bar)/$1/; The 'foo(bar)' is what is being matched and the 'bar' is captured to the $1 variable. For this: if ( $var =~ /foo(bar)/ ) { ... } The 'foo(bar)' is *still* what is being matched and the 'bar' is *still* what is being captured to the $1 variable. The first version is when you want to alter the string you're matching. The second version is good when you want to take action based upon a match and possibly extract data out of the string. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/