Perl Monk, Perl Meditation | |
PerlMonks |
Re: Searching directories for HTML title tagsby arturo (Vicar) |
on Jun 19, 2001 at 20:16 UTC ( [id://89690]=note: print w/replies, xml ) | Need Help?? |
I'll just give you some structural information, as I haven't used the latest version of HTML::Parser, a CPAN module that you should seriously consider using. One component is File::Find. You can use that to find .html, .htm, .shtml, and whatever extensions consistute "being an HTML file" as far as your webserver is concerned. File::Find</code> will recurse through subdirectories, and it's easy enough to get it to return an array of filenames. As far as finding <title> tags, the most robust solution would be to use HTML::Parser, which takes a lot of different oddities of HTML code into account (e.g. what if the content of the tag extends over two lines?). When you say you want to return the data "in an array", I'm assuming that what you want to do is store two pieces of data for each file: the name of the file, and the content of the title tag therein. Depending on your needs, you might try storing this information as a hash, where the keys are the filenames and the values are the corresponding titles. The following code will get you an array of HTML files: Update code below now uses the correct $File::Find::name, which contains the full path to the file, rather than $_, which is just the name of the file.
HTH
In Section
Seekers of Perl Wisdom
|
|