Hi,
I need to extract the word within < > and </ and > and save it to a variable. For example, <name> and </name>.
The text file has such patterns in it. I need to extract the string from those tags. I used pattern matching as under:
while(my $line1 = <FILE1>){ # for mathing <name>
if($line1 =~ /<\w+>/)
{
$words1[$i] = $1;
print "$1\n";
$i++;
}
}
and
while(my $line2 = <FILE2>){# for </name>
if($line2 =~ /<\w+\/>/)
{
$words2[$j] = $1;
print "$1\n";
$j++;
}
}
But this does not seem to give or print the correct words. I am wrong somewhere. Can anyone help with this regular expression pattern matching ?
Thanks in advance,
Priyanka
I need to extract the word within < > and </ and > and save it to a variable. For example, <name> and </name>.
The text file has such patterns in it. I need to extract the string from those tags. I used pattern matching as under:
while(my $line1 = <FILE1>){ # for mathing <name>
if($line1 =~ /<\w+>/)
{
$words1[$i] = $1;
print "$1\n";
$i++;
}
}
and
while(my $line2 = <FILE2>){# for </name>
if($line2 =~ /<\w+\/>/)
{
$words2[$j] = $1;
print "$1\n";
$j++;
}
}
But this does not seem to give or print the correct words. I am wrong somewhere. Can anyone help with this regular expression pattern matching ?
Thanks in advance,
Priyanka