Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Good Morning All

Help please! I am writing a search result page to display to metatag of documents. My question is simple, all I need to do is figure out which $triplets{"MetaTag_$i\_$j"} of metaTag contents "description" then display in first order, then "posted" displays second order. since each document written different order of metatag info.

let me repeat my question again:
1. documents are content different order of metatag, I'd like to display in the order I want and not based on HTML document itself.
2. in the same time, I'd like to disaply info when data return "description" from $triplets{"MetaTag_$i\_$j"}, same as "posted", and when "description" not exist then displays $triplets{"Summary_$i"}.

for my $j(1,2){ if(exists($triplets{"MetaTag_$i\_$j"})) { $triplets{"MetaTag_$i\_$j"} =~ s/^description=/Summary: /gi; $triplets{"MetaTag_$i\_$j"} =~ s/^posted=/Posted: /gi; print <<END_OF_HTML; <font size=-1 color="#8f8f8f" face=arial,sans-serif>$triplets{"MetaTag +_$i\_$j"}<br></font> END_OF_HTML } } # Display summary (document snippet) if there is one for my $j(1){ if (!exists($triplets{"MetaTag_$i\_$j"})) { print <<END_OF_HTML; <font color="#000000" size="-1" face=arial,sans-serif><b>Summary:</b>$ +triplets{"Summary_$i"}</font><br> END_OF_HTML } }

Replies are listed 'Best First'.
Re: return metaTag Info
by n3dst4 (Scribe) on Jan 09, 2002 at 22:42 UTC
    You want to parse out the meta tags of a document and display them in a certain order?
    # Warning: These are _crappy_ regexes and I haven't run this ($description) = $document =~ /<meta\s+name=['"]description['"]content['"]([^'"]+)['"]/; ($posted) = $document =~ /<meta\s+name=['"]posted['"]\s+content['"]([^'"]+)['"]/; print "$description, $posted\n";

    But much, much better is HTML::HeadParser. I think it does exactly what you're after (actually - it does exactly what I think you're after :) It's a lightweight HTML parser that just does the head of a document.

    I'm not sure what what your %triplets is for - have you already extracted the data and simply want to test for its presence?