On Saturday 24 November 2007 22:59, Todd wrote:
> See the codes below. The trick here is that $& is an special var used
> to capture the total match string.
> So in this case, the /[$&]/ regexp literal is equal to /
> [.type=xmlrpc&]/.

Right.  And that is a character class which says to match *one* 
character, either '.' or '=' or '&' or 'c' or 'e' or 'l' or 'm' or 'p' 
or 'r' or 't' or 'x' or 'y'.


> #!/bin/perl
> $url = 'http://abc.com/test.cgi?TEST=1&.type=xmlrpc&type=2';
> ($r1) = $url =~ /\.type=(.+?)(&|$)/;
> print "\$&=$&\n";
> ($r2) = $url =~ /\.type=(.+?)[$&]/;
>
> print "\$r1=$r1\n\$r2=$r2\n"
>
> __DATA__
> $&=.type=xmlrpc&
> $r1=xmlrpc
> $r2=x

Which is why $r2=x because (.+?) matches the 'x' after '.type=' and 
[.type=xmlrpc&] matches the 'm' after '.type=x'.

Also, using $& (or $` or $') slows down all regular expressions in the 
program.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to