in reply to Re: Meta tag
in thread Meta tag

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

Replies are listed 'Best First'.
Re^3: Meta tag
by nedals (Deacon) on Oct 21, 2005 at 01:36 UTC

    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>