Hello Jathin, The problem with the code is that its gone in to an infinite loop.. The pattern matching that u have done u need to make it global or for all occurances. .. The /g option is used to match all the patterns in the given string u can try this..
while ($catalog =~ /Perl/g) Regards Ashwin Thayyullathil Surendran #91 9884444732 On Sat, Oct 30, 2010 at 1:00 PM, Jatin <[email protected]> wrote: > 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: [email protected] > For additional commands, e-mail: [email protected] > http://learn.perl.org/ > > >
