in reply to Meta tag

I can successfully take what's between the page title tags, chop off the start/ends and print that out..

How do you do that currently? Are you using a RegEx?

A simple expanation of the above can lead to a method to extract the META data that can be incorporated into your existing script.

Replies are listed 'Best First'.
Re^2: Meta tag
by No-Lifer (Initiate) on Oct 20, 2005 at 10:59 UTC
    Currently, I use -
    if(/<TITLE>/) { chop; $title = $_; $title =~ s/<TITLE>//g; $title =~ s/<\/TITLE>//g; }
    which works well for me, and isn't too complex. If I could get that working for meta tags I'd be happy! :) Cheers for help guys

      Based on your response I conclude that this snippet is inside a while loop. I also conclude that the <title> and <meta> tags are on seperate lines.

      use strict; my ($title,$meta) = ('',''); while (<DATA>) { ## <DATA> for test chomp; # .. if (/<title>/i) { $title = $_; $title =~ s/<title>(.+?)<\/title>/$1/i; } if (/<meta/i) { $meta = $_; $meta =~ s/<meta .+? CONTENT="(.+?)">/$1/i; } #.. } print "RESULT:\n$title\n$meta\n"; __DATA__ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/T +R/html4/strict.dtd"> <html><head> <TITLE>untitled</TITLE> <META NAME="description" CONTENT="An introduction to the basics of Per +l scripting."> </head> <body> </body> </html>