Well to me Perl sometimes looks abit Abracadabra so many thanks for the patience with me...
update; joe asked me to post the full script that isnt workin: here we have the code that i have tried out after mobs answer (see below)
getting serious errors all the way long:
martin@linux-wyee:~/perl> perl test_8.pl
syntax error at test_8.pl line 25, near ")
binmode"
Global symbol "$out" requires explicit package name at test_8.pl line 25.
Global symbol "$out" requires explicit package name at test_8.pl line 26.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl> su -
here the script i run currently...
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = new WWW::Mechanize::Firefox();
open my $urls, '<', 'urls.txt' or die $!;
while (<$urls>) {
chomp;
next unless /^http/i;
print "$_\n";
$mech->get($_);
my $png = $mech->content_as_png;
my $name = $_;
$name =~ s#^http://##i;
$name =~ s#/##g;
$name =~ s/\s+\z//;
$name =~ s/\A\s+//;
$name =~ s/^www\.//;
$name .= ".png";
open(my $out, '>', "/images/$name")
binmode $out;
print $out $png;
close $out;
sleep 5;
}
and here are five sample urls...
http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
end of update; and here the original initial-thread continues...
i need to have some thumbnails from websites but i tried to use wget - but that does not work for me, since i need some rendering functions what is needet: i have a list of 2,500 URLs, one on each line, saved in a file. Then i want a script - see it below - to open the file, read a line, then retrieve the website and save the image as a small thumbnail. well since i have a bunch of web-sites (2500) i have to make up my mind about the naming of the results.
http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
http://www.phtg.ch
http://www.phsg.ch
http://www.phsh.ch
http://www.phr.ch
http://www.hepfr.ch/
http://www.phbern.ch
So far so good, well i think i try something like this
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $mech = new WWW::Mechanize::Firefox();
open my $urls, '<', 'urls.txt' or die $!;
while (<$urls>) {
chomp;
next unless /^http/i;
print "$_\n";
$mech->get($_);
my $png = $mech->content_as_png;
my $name = $_;
$name =~ s#^http://##i;
$name =~ s#/##g;
$name =~ s/\s+\z//;
$name =~ s/\A\s+//;
$name =~ s/^www\.//;
$name .= ".png";
open my $out, ">", $ "images" or die $!;
binmode $out;
print $out $png;
close $out;
sleep 5;
}
running a little script and collecting / getting results... i gather images as thumbnails. so far so good.
Note: all is nice and runs well so far untill - yes untill i tried to create a special option: i wanted to force the script to do some storing of the results in a folder
Well, what do you think about the idea of storing the results in a folder called images or so!?) is this doable? it would help alot since i get stored the results in a folder. And the many results do not mess the machine...
i run into some issues. tried to do it - to store it in a directory thusly:
open(my $out, '>', "path/$name") or die $!;
i did it like so..
note - the directory called images is in the very same folder...
i get the results
perl test_8.pl
Global symbol "$images" requires explicit package name at test_8.pl line 23.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl>
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$/images"
(Missing operator before images?)
syntax error at test_8.pl line 23, near "$/images "
Global symbol "$out" requires explicit package name at test_8.pl line 24.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$/images"
(Missing operator before images?)
syntax error at test_8.pl line 23, near "$/images "
Global symbol "$out" requires explicit package name at test_8.pl line 24.
Execution of test_8.pl aborted due to compilation errors.
martin@linux-wyee:~/perl>
martin@linux-wyee:~/perl> perl test_8.pl
Bareword found where operator expected at test_8.pl line 23, near "$ "images"
(Missing operator before images?)
String found where operator expected at test_8.pl line 23, at end of line
(Missing semicolon on previous line?)
syntax error at test_8.pl line 23, near "$ "images"
Can't find string terminator '"' anywhere before EOF at test_8.pl line 23.
martin@linux-wyee:~/perl>
Your original post included the code
open(my $out, '>', "path/$name")
which is very much on the right track. To write a file whose name is contained in $name
in the directory images
, the correct syntax is
open(my $out, '>', "images/$name")
I'm not sure how you got off track and tried $images
, $/images
, and $ images
.