netroact
04-06-2008, 08:30 PM
I am using the following code to snatch the title out of a web page:
# Read file
open(FILE,"<$home_dir/$main_category/$sub_category/$file") || die "Could not open file for reading! $!";
while(<FILE>)
{
#grab the title from web page
$_ =~ s/^<title>(.*)<\/title>$/$1/ if ($_ =~ /^<title>(.*)<\/title>$/);
$title = $1;
}
close FILE || die "Could not close file! $!";
This works, but I would like to learn something, and I've lost patience.
How can I read the title into the $title variable without another line and without using $1?
I would think I could just do this:
$_ =~ s/^<title>(.*)<\/title>$/$title/ if ($_ =~ /^<title>(.*)<\/title>$/);
But, it doesn't work.
Thanks!
# Read file
open(FILE,"<$home_dir/$main_category/$sub_category/$file") || die "Could not open file for reading! $!";
while(<FILE>)
{
#grab the title from web page
$_ =~ s/^<title>(.*)<\/title>$/$1/ if ($_ =~ /^<title>(.*)<\/title>$/);
$title = $1;
}
close FILE || die "Could not close file! $!";
This works, but I would like to learn something, and I've lost patience.
How can I read the title into the $title variable without another line and without using $1?
I would think I could just do this:
$_ =~ s/^<title>(.*)<\/title>$/$title/ if ($_ =~ /^<title>(.*)<\/title>$/);
But, it doesn't work.
Thanks!