CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
$str =~ s{>([^<>]+?)<(?{ local $l = $1;})}{($l !~

 



ebu
stranger

Dec 4, 2001, 5:42 AM

Post #1 of 4 (7062 views)
$str =~ s{>([^<>]+?)<(?{ local $l = $1;})}{($l !~ Can't Post

Please, look at this. Why $l starts beeing initialized only first match? (Constractig this re i guessed like this: i need find (mark *x*) everyhting between > and <: ([^<>]+?) which is not newlines and blank spaces: ($l !~ /\w/) ?">$1<":">*$l*<" )


#!/usr/bin/perl

use strict;
#my $str = qq{<html><b> <c><p>aaaaaaa</p> - if blankspace betwean b and c present - aaaaa matches

my $str = qq{<html><b><c><p>aaaaaaa</p>
<p>bbbbbbb</p>
<p>ccccccc</p>
<p>ddddddd</p>
<p>eeeeeee</p>
<p>fffffff</p>
<p>ggggggg</p>
</html>};

my $l = '';
$str =~ s{>([^<>]+?)<(?{ $l = $1;})}{($l !~ /\w/) ?">$1<":">*$l*<"}gexsmi;


print "Content-type: text/html\n\n";
print $str."\n";




fashimpaur
User

Dec 4, 2001, 6:34 AM

Post #2 of 4 (7058 views)
Re: $str =~ s{>([^<>]+?)<(?{ local $l = $1;})}{($l !~ [In reply to] Can't Post

But you do not make it clear what you are trying to do. Can you clarify your desired result?

Dennis

$a="c323745335d3221214b364d545a362532582521254c3640504c37292f493759214b3635554c3040606a0",print unpack"u*",pack "h*",$a,"\n\n"


ebu
stranger

Dec 4, 2001, 6:41 AM

Post #3 of 4 (7055 views)
Re: $str =~ s{>([^<>]+?)<(?{ local $l = $1;})}{($l [In reply to] Can't Post

I want to mark all text in html. I.e. to find all in <tag>mark this</tag>
and, yeah, sorry, i meant
Why $l starts beeing initialized only AFTER first match?



thebitch
User

Aug 9, 2002, 7:18 AM

Post #4 of 4 (6357 views)
Re: [ebu] $str =~ s{>([^<>]+?)<(?{ local $l = $1;})}{($l [In reply to] Can't Post

you're using the wrong tool for the job.
use HTML::Parser or HTML::TokeParser
or something similar (XML::Parser or what have you)

$l starts being "initialized" only after the
first match because you're assigning $1 to it.
$1 will only contain a value after you match something,
which happens after you match something, so until
you match something, $1 will not be defined
( it will be uninitialized).
addd

Code
use re 'debug';

to the top of your script to see extra debugging output

You've chosen the wrong approach, and that
hairy regex ain't gonna cut it (it can be fooled).
please go to CPAN and get yourself a HTML parser,
they're very easy to use, easier than Regular Expressions

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives