
Kanji
User
/ Moderator
Sep 11, 2000, 10:04 PM
Post #4 of 5
(1989 views)
|
Save it to a file (ie, "contains.pl"), make sure the file is executable (ie, "chmod 700", perhaps 755) if your OS warrants it, and then run it from your favourite command line shell as ... contains.pl http://www.perlguru.com/ kanji ... where http://www.perlguru.com/ is the URL you want to look at, and kanji is the text to look for. Depending on your setup, you may also need to prepend that with "perl" or "/path/to/perl". How this works is by including one of the WWW libraries for perl (LWP = LibW(rary)WW-Perl), and using it's &get() subroutine to save the content of the target page to a variable. We then search that variable to see if it contains the wanted text and report accordingly. If you're confused by the print expr ? a : b construct, it's fucntionally the same as ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> if ( expr ) { print a } else { print b }</pre><HR></BLOCKQUOTE> Finally, the regexp gets broken down as ... \b = search for a word boundry (so that if you entered the word "all" it won't match "small". \Q = disable search metacharacters which have special meanings inside regular expressions so that if you wanted the word ".(" it would work without blowing up your script by making it look for the matching ")". See the perlre documentation page. \E = re-enables the use of search metacharacters. \b = another search boundry, so that the word "old" won't match "goldden". Finally, /i make the search case-insensitive. Two other things: there was a typo in the code which I'll fix after this ( /b should have been /\b ), and UBB did its usuall trick of inserting a space inbetween the | |'s so it may not have run beforehand.
|