Appy16 has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a script that checks the Status of URLs every hour and then respond to a few other functions. The script needs to copy URLs from a text file that is stored on a base folder location and check their status. For running the script every hour i am using cron. Till now i have reached the checking part but the problem is that i am not able to read the URL from file to the checking part.

Checking Part here refers to the part where the status of URL is checked.

Kindly Help. Thanx in advance.
#!/usr/bin/perl use warnings; use LWP::Simple; require LWP::UserAgent; use Tie::File; my $testfolder = "/Users/Appy/Desktop/"; tie @file, 'Tie::File', $testfolder . "testfile.txt" or die; print "$file[1]\n"; untie @file; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get($file[1]); if ($response->is_success) { print "The URL is active.\n"; } else { print "The URL is Inactive.\n"; }

Replies are listed 'Best First'.
Re: Perl copy Text from file to Script
by almut (Canon) on Mar 22, 2010 at 08:37 UTC
    print "$file[1]\n"; ... my $response = $ua->get($file[0]);

    So what do you get when you print out $file[0] instead of $file[1]? Does it hold the URL?  Or, in case $file[1] should hold the URL, what happens if you pass it to ->get()?

      If $file[0] = www.abcd.com and $file[1] = www.google.com. I get "www.abcd123.com" when i print $file[0] and "www.google.com" when i print $file[1]. Yes both File[0] and file[1] hold URLs. Whether I pass $file[0] to ->get( ) or $File[0] to ->get( ). I always get :

      The URL is Inactive.

      But if I directly pass http://www.google.com to ->get( ) I get :

      The URL is active.

        Well, there's one difference between what you pass via $file[0] and what you pass directly: the latter one has the protocol specifier "http://".  So, I would try $ua->get("http://$file[0]").

Re: Perl copy Text from file to Script
by Utilitarian (Vicar) on Mar 22, 2010 at 10:30 UTC
    You have dropped the association before making your request. untie @file; should be called after you no longer need the @file array to be associated with the file

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."