SPUG: Self referecing URL

Joel Grow largest at largest.org
Fri Sep 22 21:16:12 CDT 2000


On Fri, 22 Sep 2000, marlin wrote:

> I need to detect a catalog number in a text line and reference it to
> another page as a link.
> 
> The text is $item_text. I want to swap the number (NUM + some digits)
> with itself as a <A HREF> tag.
> 
> I tried...
> 
> $item_text =~ s/(NUM.*\s)/<A HREF=get_page.pl?cat_num=\1>\1</A>/g;
> which sort of works except that the closing > after the \1 is ignored,
> that is the tag never closes and the entire line is linked.


One problem is that the / in '</A>' isn't escaped, so Perl thinks that /
is the regex delimiter.  You can fix that with a \ (in other words, change
it to '<\/A>').  Also, the .* in the first part of the regex might also be
causing you problems.  If you're looking for NUM followed by as many
digits as possible (up to a space, I'm guessing based on your \s), you
could do:

 $item_text =~ s/(NUM\d+)/<A HREF=get_page.pl?cat_num=\1>\1<\/A>/g;

HTH

Joel


> Marlin Greene
> -- 
> 	3 Hats Design
> 	INTERNET  PRINT  ILLUSTRATION
> 	5201 15 Ave NW 
> 	Suite 220
> 	Seattle, WA 98107
> 	206.784.1641 phone
> 	206.784.2231 fax
> 	marlin at 3hats.com
> 	http://www.3hats.com



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list