Tuxedo <
tux...@mailinator.com> writes:
> Many thanks for all the replies in showing the numerous ways of doing more
> or less the same thing. In the end I just used somothing as follows, as
> taken from one of the replies:
>
> system "ls *.JPG > list.txt"; # from remote
>
> open (my $fh, "<", "list.txt") or die "can't open file: $!";
> my @lines = <$fh>;
>
> my $array_entry;
>
> system "wget --delete-after --secure-protocol=auto --http-user=***
> --http-password=*** \"http://***/img.php?f=$array_entry&x=200\"";
>
> }
>
I think some code disappeared there. I assume you are iterating over the
array?
Your code then should look something like:
for my $array_entry (@lines) {
system etc...
}
That, however, makes reading the file redundant, as there is an idiom
for that:
while (my $array_entry = <$fh>) {
system etc...
}
This is standard idiom to read a file line-by-line, the <$fh> line input
operator in scalar context will read the next line until EOF, when it
will return false and terminate the while loop.
But if you're going this route, you don't have to first redirect to a
file. Your code above assumes you're running the script in the directory
the files are in, so instead of using system to use ls to create a file
with all *.JPG files and then iterating over every line in the file, you
can use the glob operator instead (which, confusingly, looks like the
line-input operator):
my @jpgs = <*.JPG>
for my $array_entry (@jpgs) {
system etc...
}
And even more perly would be to replace the system call with some code
using LWP::UserAgent or WWW::Mechanize.