R
Ravi Parimi
Hi,
I have a string that gets generated on the fly. Based on the
number of times a particular word appears in this string, I generate my
matching pattern. As an example..
$string = "<Data><Size>12</Size>one string<Size>100</Size>Another
string</Data>";
Now, based on the number of <Size> tags in the string, I create a regular
expression such as
my $count = $string =~ s#<Size>##gs;
my $str = "";
for ($i = 1;$i <= $count;++$count) {
$str .= "<Size>(\\d+)</Size>(.*)";
}
And now I wish to extract all odd-numbered match variables from the
matching($1, $3, $5 etc..)
$string =~ /$str/; # Match always succeeds as I know what's in $string
In a for loop, I wish to check if each of the $1,$2,$3...variables are
defined, and am not quite sure how to do that.
Usage of ${$i} is incorrect and doesnt make sense. Can someone suggest a
method by which I can find out if $1, $2, $3 ..are defined?
As an alternative, I have tried XML Parser to parse the above string but
had no luck with it.. Any help is appreciated.
Thanks,
--ravi
I have a string that gets generated on the fly. Based on the
number of times a particular word appears in this string, I generate my
matching pattern. As an example..
$string = "<Data><Size>12</Size>one string<Size>100</Size>Another
string</Data>";
Now, based on the number of <Size> tags in the string, I create a regular
expression such as
my $count = $string =~ s#<Size>##gs;
my $str = "";
for ($i = 1;$i <= $count;++$count) {
$str .= "<Size>(\\d+)</Size>(.*)";
}
And now I wish to extract all odd-numbered match variables from the
matching($1, $3, $5 etc..)
$string =~ /$str/; # Match always succeeds as I know what's in $string
In a for loop, I wish to check if each of the $1,$2,$3...variables are
defined, and am not quite sure how to do that.
Usage of ${$i} is incorrect and doesnt make sense. Can someone suggest a
method by which I can find out if $1, $2, $3 ..are defined?
As an alternative, I have tried XML Parser to parse the above string but
had no luck with it.. Any help is appreciated.
Thanks,
--ravi