At 19:12 +0100 1/12/11, Marek Stepanek wrote, and I snipped a bunch:
>Hello all!
>
>#!/usr/bin/perl
>use strict;
>use warnings;
>
>$/ = undef;
>$_ = <>;
>
>foreach ($_ =~ m,(</p>\s+[^<]+?<p),g) {
> my $paragraf = $1;
> $paragraf =~ s,</p>,$&<p class="links_normal">,;
> $paragraf =~ s,\n\n<p$,</p><p,g;
> $paragraf =~ s,\n,<br>,g;
> $paragraf =~ s!\s{2,}!!g;
> print $paragraf;
> $paragraf = ();
>}
>
>print;
*****
The $& may be referring to the last match as it occurs in a previous loop
operation instead of what you think.
But why do you need the loop at all? The g flag will repeat each substitute
over the whole text if the target is $_ instead of $paragraf. In the loop you
probably don't want the g's at all.
$/ = undef;
$paragraf = <>;
$paragraf =~ s,</p>,$&<p class="links_normal">,g;
$paragraf =~ s,\n\n<p$,</p><p,g;
$paragraf =~ s,\n,<br>,g;
$paragraf =~ s!\s{2,}!!g;
print $paragraf;
I may well be missing something like being sure not to replace accidental
matches. Aren't those commas dangerous? You can use anything as the separator
but I prefer the pipe symbol when trying to avoid /\/ teepees. You may also
need a ///s flag to allow matching of return characters. And come to think of
it are they \n or might they be \r in BBEdit tradition?
--
--> The best programming tool is a soldering iron <--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>