Search code examples
perlparsingstorewww-mechanize

How to arrange the output from Perl :: Mechanize in a concise order (with variables or names)


I run linux opensuse 11.4. I try to run this little programme on a linux box.

#!/usr/bin/perl

    use WWW::Mechanize::Firefox;
    my $mech = WWW::Mechanize::Firefox->new();

    open(INPUT, "urls.txt") or die "Can't open file: $!";

    while (<INPUT>) {
      chomp;
      $mech->get($_);
      my $png = $mech->content_as_png();
    }
    close(INPUT);
    exit; 

I have a list of URLS - more than 1000 URLS - so it might be a problem if I get the results in an unsorted way.

I have a list of 1000 URLs, one on each line, saved in a file. I want the script above to open the file, read a line, then retrieve the website! The URLS are stored something like this:

    Filename: urls.txt
    ------------------
    www.google.com
    www.cnn.com
    www.msnbc.com
    news.bbc.co.uk
    www.bing.com
    www.yahoo.com 

How can I write the script so that the thumbnail-images are stored with certain names - e.g., with the domain names. Otherwise the results would be a whole mess. I need to identify the thumbnails based on the URLS. Is this possible?


Solution

  • open my $out, '>', "$_.png" or die "could not open '$_.png' for output $!";
    print $out $png;
    close $out;