Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Call for code samples!

by jepri (Parson)
on Nov 15, 2001 at 19:36 UTC ( [id://125587]=note: print w/replies, xml ) Need Help??


in reply to Call for code samples!

This is probably the nastiest regex I ever had to use. It's goal was to highlight Extended Letter Sequences in text. The ELS had already been found, this routine went through and turned the letters of the hidden word into uppercase. This is just a 'capitalise every nth letter' challenge, and I cheated by stripping out the spaces first:

#Block is the chunk of text, word is the 'hidden' word and sep is the +number of characters in the text between each word my ($block, $sep, $word)=@_; my @let = split //, $word; my $rep; my $i=1; foreach my $l (@let) {$l = "(".$l.")(.{$sep})";$rep.= + '\u$'.$i++.'$'.$i++;}; my $regexp2 = join "", @let; my $ev = '$block =~ '."s/$regexp2/$rep/i;"; # print "Now scanning block with $regexp2 and replacemen +t target $rep\n"; return $block, $word if eval $ev;

The output looks like this:

---This is the original text---------------------------------------- m at times; this thread, like that of Ariadne, when once unraveled will conduct one through a lab ---The ELS 'FNORD' is in capitals--------------------- mattimesthisthreadlikethatoFariadNewhenOnceunRaveleDwillconductonethro +ughalab

BTW if there's an obviously better way to do this I'd be delighted to hear about it.

____________________
Jeremy
I didn't believe in evil until I dated it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found