This is a small perl script I wrote to check mirror lists (files filled with one URL per line). It prints "[FAIL] hxxp://..." when an URL can't be retrieved and just prints the url when everything goes fine. The code is pretty straightforward and it works well until I am trying to redirect its output.
There is one thing I can't figure out. As far as I know the program called '
less' prints its input on the screen providing a nice interface for examining the contents of another program's output.
less works fine in situations like:
Code:
perl -e 'print "test"' | less
ls | less
cat /etc/passwd | less
The problem is that using my script '
less' only gets the lines sent to STDERR.
linkchk.pl
Code:
#!/usr/bin/perl
#
# Usage: ./linkchk.pl filename_containing_urls
# or cat file | ./linkchk.pl
use LWP;
$ua=LWP::UserAgent->new;
$ua->timeout(3);
$req=HTTP::Request->new;
$req->method("HEAD");
# create and urllist file
# try ./linkchk.pl urllist | less
print STDOUT "Why can't ./linkchk.pl urllist|less see this?\n";
while (<>)
{
chomp($line=$_);
$req->uri($line);
$res=$ua->request($req);
if ($res->is_success)
{
print STDOUT "$line\n";
}
else
{
print STDERR "[FAIL] $line\n";
}
}
any clues?
(Fedora9, perl 5.10.0)