Hi All,
   I'm no expert at regexps. I've done the following code to get some SEO details from the page of HTML. The only problem is it isn't fast. In fact it's plain slow. Can any genius out there give me a hand? The script will potentially be called quite a lot, I don't want it chewing up all my servers CPU.
while ($html =~ /\b$WHATWANT{'term'}'?s?\b/gis) { $termstotal++; } ## +End while while ($html =~ /<body>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/body>/gis) { +$termsbody++; } ## End while while ($html =~ /<title>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/title>/gis) +{ $termstitle++; } ## End while while ($html =~ /<h1.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h1>/gis) { $ +termshead1++; } ## End while while ($html =~ /<h2.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h2>/gis) { $ +termshead2++; } ## End while while ($html =~ /<h3.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h3>/gis) { $ +termshead3++; } ## End while while ($html =~ /<h4.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h4>/gis) { $ +termshead4++; } ## End while while ($html =~ /<h5.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h5>/gis) { $ +termshead5++; } ## End while while ($html =~ /<h6.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/h6>/gis) { $ +termshead6++; } ## End while while ($html =~ /alt=\".*?\b$WHATWANT{'term'}'?s?\b.*?\"/gis) { $terms +alt++; } ## End while while ($html =~ /alt=\'.*?\b$WHATWANT{'term'}'?s?\b.*?\'/gis) { $terms +alt++; } ## End while while ($html =~ /<a .*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/a>/gis) { $t +ermsa++; } ## End while while ($html =~ /<\!--.*?\b$WHATWANT{'term'}'?s?\b.*?-->/gis) { $terms +comment++; } ## End while while ($html =~ /<li.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/li>/gis) { $ +termsbullet++; } ## End while while ($html =~ /href=\".*?$WHATWANT{'term'}'?s?.*?\"/gis) { $termshre +f++; } ## End while while ($html =~ /href=\'.*?$WHATWANT{'term'}'?s?.*?\'/gis) { $termshre +f++; } ## End while while ($html =~ /<p.*?>.*?\b$WHATWANT{'term'}'?s?\b.*?<\/p>/gis) { $te +rmsp++; } ## End while


Thanks

In reply to Slow regexp by cosmicperl

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.