[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] R/E Question



>>>>> "MGS" == Michael G Schwern <schwern@pobox.com> writes:

hey schwern,

i know you can take some comments unlike some people i have seen. :-)


  MGS>     $$text =~ s/($uriRe)/

you are doing a very long s///x which is hard to read. i would do
something like this


	$$text =~ s/($uriRe)/process_uri($1)/e ;

and make the rest of the code into a sub. that eliminates the need for
all the \ and allows you do use return and other sub stuff you can't do
in a s///e.

  MGS>       $uri_cand = $1;
    
  MGS>       $uri_cand =~ s|[\)\,\.]+$||;

no need to \ those in a char class. sometime a single ) canbe escaped to
make emacs happy.
    
  MGS>       $uri =~ s|^www\.|http:\/\/www\.|;

same as before, . does not need escaping in the replacement string.

i did something similar a couple of years ago looking for web addresses
in text when converting to html. it wasn't as thorough but it seem to
convert most of them just fine. handling the trailing punctuation was
one of the trickiest parts. it also needed /ex and it was one of the
first times i used those modifiers.
   
uri


-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe