Hi All
I had a sample code from the Perl&LWP book. It was the very first code i
was trying out in different ways. Firstly the actual code mentioned in
the book was as below:
----------------------------------------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
my $catalog = get("http://oreilly.com/store/complete.html");
my $count = 0;
while ($catalog =~ /Perl/gi) {
$count++;
}
print "Perl was seen the following number of times in the page : $count \n";
------------------------------------------------------------------------
I had modified this code in a small way as shown below and this code
never executed to completion and it was causing 100% CPU usage on my
laptop where it was being run.
-------------------------------------------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
my $catalog = get("http://oreilly.com/store/complete.html");
my $count = 0;
while ($catalog =~ /Perl/) {
$count++;
}
print "Perl was seen the following number of times in the page : $count \n";
---------------------------------------------------------------------------
The only place where it was changed was in the pattern matching area
where i removed the usage of all the modifiers. can some one please
answer the following questions for me:
1. Why is the CPU being used so much ? Is the code going in some sort of
a loop ?
2. Does $catalog take single string from and match for the pattern ?
In this case i am under the impression that the entire value
returned by the get() method is stored in the $catalog variable. Please
correct me if i am wrong.
Appreciate your response in this regard.
Thanks
Jatin
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/