Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Call for code samples!

by chromatic (Archbishop)
on Nov 16, 2001 at 00:51 UTC ( [id://125669]=note: print w/replies, xml ) Need Help??


in reply to Call for code samples!

I don't see anything in the substitution chapter that directly uses one of my favorite techniques -- calling subs on the rhs of a substitution. It may be obvious, if you think about it, but it's worth discussion. Everything (and Slash) handle links in textfields with something like this:
$text =~ s/\[([^\]]+)\]/parseLink($1)/eg; sub parseLink { my $link = shift; my ($type, $title); ($type, $link, $title) = $link =~ m!(.+)://(.+)|(.+)!; $type ||= ''; $title ||= $link; return makeLink($link, $title, $type); }
Somewhat hastily reconstructed out of memory. It's a little more optimized in the code, I believe. It's also a very nice way to handle more complex transformations.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125669]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found