Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: 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.

use File::Find; use HTML::Parser; # this code doesn't make use of the module, but I r +eally think you should use it in your code =) my @data; find(\&html_files, "/base/path"); # now process @data, which is a list of filenames sub html_files { push @data, $File::Find::name if /\.s?html?$/; }


perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

In reply to Re: Searching directories for HTML title tags by arturo
in thread Searching directories for HTML title tags by arashi

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2021-04-22 23:48 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found