T
Todd W
A factory function we have makes some stupid assumptions about the data it
is parsing. I give it content and a regex, and it gives me back an array.
Is there any way, for example, to tell capture 1 of a regex to store its
value in $2?
Here is the output of the program below.
[trwww@waveright misc]$ perl cap.pl
One:
title: bar
link: foo
descr: bazz
Two:
title: bazz
link: bar
descr: foo
Is there any way to make the output of "One:" identical to the output of
"Two:" by changing ONLY the the string stored in $reg2?
use warnings;
use strict;
my $str1 = '<a href="foo">bar</a><div>bazz</div>';
my $reg1 = '<a href="([^"]+)">([^<]+)</a><div>([^<]+)<';
$str1 =~ m|$reg1|;
print("One:
title: $2
link: $1
descr: $3
");
my $str2 = '<div>bar</div><div>bazz</div><a href="foo">readmore</a>';
### modify only this regex
my $reg2 = '<div>([^<]+)</div><div>([^<]+)</div><a href="([^"]+)"';
$str2 =~ m|$reg2|;
print("Two:
title: $2
link: $1
descr: $3
");
Thanks in advance,
Todd W.
is parsing. I give it content and a regex, and it gives me back an array.
Is there any way, for example, to tell capture 1 of a regex to store its
value in $2?
Here is the output of the program below.
[trwww@waveright misc]$ perl cap.pl
One:
title: bar
link: foo
descr: bazz
Two:
title: bazz
link: bar
descr: foo
Is there any way to make the output of "One:" identical to the output of
"Two:" by changing ONLY the the string stored in $reg2?
use warnings;
use strict;
my $str1 = '<a href="foo">bar</a><div>bazz</div>';
my $reg1 = '<a href="([^"]+)">([^<]+)</a><div>([^<]+)<';
$str1 =~ m|$reg1|;
print("One:
title: $2
link: $1
descr: $3
");
my $str2 = '<div>bar</div><div>bazz</div><a href="foo">readmore</a>';
### modify only this regex
my $reg2 = '<div>([^<]+)</div><div>([^<]+)</div><a href="([^"]+)"';
$str2 =~ m|$reg2|;
print("Two:
title: $2
link: $1
descr: $3
");
Thanks in advance,
Todd W.