You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Gavin Spomer <ga...@solaris.ellensburg.com> on 2000/10/18 22:25:31 UTC

Embperl And Matching

Does embperl have it's own $1, $2, etc. like the ones captured when using parenthesis in a matching expression? If not, does embperl do something to these 
variables produced by the parenthesis (like discard or ignore them)? To illustrate what I'm talking about here's some embperl code:

[- $text = 'This: http://www.blah.com is a url'; -]

[$ if $text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i $]
	[+ $1 +]<a href="[+ $2 +]">[+ $2 +]</a>[+ $3 +]
[$ else $]
	[+ $text +]
[$ endif $]

Which, I don't know why, produces the output:

<a href=""></a>

The equivelant (I think) non-embedded perl code:

$text = 'This: http://www.blah.com is a url';

if ($text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i )
{
	print "$1<a href=\"$2\">$2<\/a>$3\n";
}
else
{
	print "$text\n";
}

outputs what I am trying to achieve w/ the embperl code:

This: <a href="http://www.blah.com">http://www.blah.com</a> is a url

so why doesn't the embperl version work?

- Gavin

"People are the worst drivers in the world" 
http://www.singlespeedsanonymous.com/

Join PayPal and get FIVE FREE DOLLARS (no joke!):
https://secure.paypal.x.com/refer/pal=gavinspomer%40hotmail.com
... and it's a very usefull account to have!




Re: Embperl And Matching

Posted by ___cliff rayman___ <cl...@genwax.com>.
embperl is really not doing anything special, but the [$ $] blocks are not in
the same scope as the [+ +] blocks. use a global variable to capture the values
so it is available in the other blocks.

try:
[$ if @regex=($text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i) $]
        [+ $regex[0] +]<a href="[+ $regex[0] +]">[+ $regex[1] +]</a>[+ $regex[2] +]

Gavin Spomer wrote:

> Does embperl have it's own $1, $2, etc. like the ones captured when using parenthesis in a matching expression? If not, does embperl do something to these
> variables produced by the parenthesis (like discard or ignore them)? To illustrate what I'm talking about here's some embperl code:
>
> [- $text = 'This: http://www.blah.com is a url'; -]
>
> [$ if $text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i $]
>         [+ $1 +]<a href="[+ $2 +]">[+ $2 +]</a>[+ $3 +]
> [$ else $]
>         [+ $text +]
> [$ endif $]
>
>

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: Embperl And Matching

Posted by Aaron Johnson <so...@gina.net>.
As I was writing my reply I see ___cliff rayman___ has already responded.

I attempted it with his revised code and it still did not work until I add the
[- $optRawInput = 1 -] at the top.

Another way to do the process (just because that is what is great about Perl) is:

[- $optRawInput = 1 -]
[- $text = 'This: http://www.blah.com is a url'; -]
[# don't need the if since the value of $text will only change if there #]
[# is a valid http URL present #]
[- $text =~ s#(.*\s)(http\:\/\/\S+)(\s.*)#$1<a href="$2">$2</a>$3\n#i -]
[+ $text +]

Aaron Johnson

Gavin Spomer wrote:

> Does embperl have it's own $1, $2, etc. like the ones captured when using parenthesis in a matching expression? If not, does embperl do something to these
> variables produced by the parenthesis (like discard or ignore them)? To illustrate what I'm talking about here's some embperl code:
>
> [- $text = 'This: http://www.blah.com is a url'; -]
>
> [$ if $text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i $]
>         [+ $1 +]<a href="[+ $2 +]">[+ $2 +]</a>[+ $3 +]
> [$ else $]
>         [+ $text +]
> [$ endif $]
>
> Which, I don't know why, produces the output:
>
> <a href=""></a>
>
> The equivelant (I think) non-embedded perl code:
>
> $text = 'This: http://www.blah.com is a url';
>
> if ($text =~ /(.*\s)(http\:\/\/\S+)(\s.*)/i )
> {
>         print "$1<a href=\"$2\">$2<\/a>$3\n";
> }
> else
> {
>         print "$text\n";
> }
>
> outputs what I am trying to achieve w/ the embperl code:
>
> This: <a href="http://www.blah.com">http://www.blah.com</a> is a url
>
> so why doesn't the embperl version work?
>
> - Gavin
>
> "People are the worst drivers in the world"
> http://www.singlespeedsanonymous.com/
>
> Join PayPal and get FIVE FREE DOLLARS (no joke!):
> https://secure.paypal.x.com/refer/pal=gavinspomer%40hotmail.com
> ... and it's a very usefull account to have!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org