G
George
Dear All,
I am parsing a web page with the LWP module and then doing some regular
expression matching to print out specific chunks of code. The way I
organised it is:
while (regular expression matches) {
process_text($1);
}
So far, everything is fine - however I noticed the following with the
subroutine: if I write code as following using $_[0], then the next time
within the same subroutine that I use it to check against another
regular expression it is empty.
$_[0] =~ m{<span class="listing_default">(.*?)</span></a>\s*</div>}si;
$title=$1;
$mtc1 = $_[0] =~ m{<div class="listing_results_rating">(.*?)</div>}si;
if ($mtc1) {
$rating=0;
}
else {
$rating=$1;
}
But if use shift and save the value in a variable, it works fine, i.e.:
my $ocontent = shift;
$ocontent =~ m{<span class="listing_default">(.*?)</span></a>\s*</div>}si;
$title=$1;
$mtc1 = $ocontent =~ m{<div class="listing_results_rating">(.*?)</div>}si;
if ($mtc1) {
$rating=0;
}
else {
$rating=$1;
}
If anyone could shed some light on why this is the case, I would be
grateful.
Regards,
George
I am parsing a web page with the LWP module and then doing some regular
expression matching to print out specific chunks of code. The way I
organised it is:
while (regular expression matches) {
process_text($1);
}
So far, everything is fine - however I noticed the following with the
subroutine: if I write code as following using $_[0], then the next time
within the same subroutine that I use it to check against another
regular expression it is empty.
$_[0] =~ m{<span class="listing_default">(.*?)</span></a>\s*</div>}si;
$title=$1;
$mtc1 = $_[0] =~ m{<div class="listing_results_rating">(.*?)</div>}si;
if ($mtc1) {
$rating=0;
}
else {
$rating=$1;
}
But if use shift and save the value in a variable, it works fine, i.e.:
my $ocontent = shift;
$ocontent =~ m{<span class="listing_default">(.*?)</span></a>\s*</div>}si;
$title=$1;
$mtc1 = $ocontent =~ m{<div class="listing_results_rating">(.*?)</div>}si;
if ($mtc1) {
$rating=0;
}
else {
$rating=$1;
}
If anyone could shed some light on why this is the case, I would be
grateful.
Regards,
George