spydermonkey
Programmer
This IS reinventing the wheel but it's a learning process as this is my first attempted module. It mimics LWP in the way you use meta_gather($url) to extract the source code, but specifically just the meta tags.
This worked FINE before I added all the IF tests when I used $count like $array[$count] = "$1::$2";. But after I added all the tests to insert things in the proper order (as outlined with the # numbers) no results are displayed (just a bunch of new lines).
Can someone help me figure out the bug? PerlGoodies is a temp name btw, lol, it will be changed later.
ALSO, how do I export variables back into the script calling it? The @meta_results won't be printed in the module, it's for testing, but I need to pass it to the script somehow so the user can do whatever they want with this array. Can someone help me out with that?
This worked FINE before I added all the IF tests when I used $count like $array[$count] = "$1::$2";. But after I added all the tests to insert things in the proper order (as outlined with the # numbers) no results are displayed (just a bunch of new lines).
Can someone help me figure out the bug? PerlGoodies is a temp name btw, lol, it will be changed later.
ALSO, how do I export variables back into the script calling it? The @meta_results won't be printed in the module, it's for testing, but I need to pass it to the script somehow so the user can do whatever they want with this array. Can someone help me out with that?
Code:
package PerlGoodies;
use Exporter;
@ISA = 'Exporter';
@EXPORT_OK = qw(meta_gather);
use strict;
sub meta_gather($)
{
use LWP::Simple;
require HTTP::Status;
my($url) = @_;
my $p_content = get($url);
my @meta_results;
my $count = 0;
#1 = description
#2 = keywords
#3 = abstract
#4 = author
#5 = robots
#6 = distribution
#7 = language
#8 = rating
#9 = copyright
#10 = distributor
while($p_content =~ /<meta\s+name=\"(.+?)\"\s+content=\"(.+?)\">/ig)
{
$count++;
if($1 =~ /^description$/i)
{
$meta_results[1] = "$2";
}
elsif($1 =~ /^keywords$/i)
{
$meta_results[2] = "$2";
}
elsif($1 =~ /^abstract$/i)
{
$meta_results[3] = "$2";
}
elsif($1 =~ /^author$/i)
{
$meta_results[4] = "$2";
}
elsif($1 =~ /^robots$/i)
{
$meta_results[5] = "$2";
}
elsif($1 =~ /^distribution$/i)
{
$meta_results[6] = "$2";
}
elsif($1 =~ /^language$/i)
{
$meta_results[7] = "$2";
}
elsif($1 =~ /^rating$/i)
{
$meta_results[8] = "$2";
}
elsif($1 =~ /^copyright$/i)
{
$meta_results[9] = "$2";
}
elsif($1 =~ /^distributor$/i)
{
$meta_results[10] = "$2";
}
}
foreach (@meta_results) { print "$_\n";}
return;
}
1;
__END__