If you want to see if a word is on a webpage, the first step is to get the webpage. There are many Perl tools for doing that. The most basic of these is: LWP::Simple. There are other tools, Mechanize is one, also LWP::UserAgent.

This whole subject can get complicated if you have to fill in forms and do more complex types of interactions with the web server. You didn't provide any information about what kind of webpage's you want to access. But basically it is possible to get any page that you as a human could while clicking around on a website. LWP Cookbook may be useful. Let us know how you get on after trying some simple stuff.

Update:
As possible alternate to your code, see below. No need to split, you can use a match global. The \Q\E pair says to interpret text in $word literally (in case funny characters are in there). The \b says to match on a word boundary - this is why the "thisthis" does not match.

#!/usr/bin/perl -w use strict; my $count; my $word = "this"; while (<DATA>) { my @matches = /\b\Q$word\E\b/gi; $count += @matches; # # or just do this: # $count+= () = /\b\Q$word\E\b/gi; } print "$count"; #prints 3 # note that the last "thisthis" on line 1 # doesn't count! Also note that multiple "this" on # same line are counted. __DATA__ this is the text that this thisthis abd this
This is of course just the functionality of command line grep. There are Windows variants free on the web - search Windows grep, or gnu grep.

In reply to Re: Perl code to check and count count if a word exists on a webpage by Marshall
in thread Perl code to check and count count if a word exists on a webpage by Thakur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.