vroom has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on some code that will allow arbitrary textual substitutions on anything that is outside of a given set of blocks ie... outside of <CODE>.*?<\CODE;> or outside of HTML tags. The first reason I want this is to split up long words in the chatterbox without breaking URLS.
So here's some test code I've been playing with.
#!/usr/bin/perl my $string="realllylongstringthatrefusestoend". " <A HREF=\"http://perlmonks.org/images/blah/blah/blah\">\n"; print splitter($string,"<.*?>","\S{18}","$1 "); sub splitter{ my($string,$spliton,$find,$replace)=@_; my @array=split(/$spliton/,$string); my $i=0; my @splitters; my $str; while($string=~/($spliton)/g){ push @splitters,$1; } for(@array){ #none of these work #s/$find/$replace/eeg; #s/$find/$1 /g; #eval '$string' . " =~ s/$find/$replace/"; #this works s/(\S{18})/$1 /g; $str.=$array[$i]; $str.=$splitters[$i]; $i++; } $str; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling scalars as regexs within a substitution. (Take 2)
by ZZamboni (Curate) on May 22, 2000 at 20:20 UTC | |
|
RE: Handling scalars as regexs within a substitution. (Take 2)
by ZZamboni (Curate) on May 22, 2000 at 22:09 UTC | |
|
Re: Handling scalars as regexs within a substitution. (Take 2)
by Anonymous Monk on Oct 24, 2001 at 18:07 UTC |