Hi, I am so confused. I created a small script to download some files from a server. These are configs visible in webpages. We need to automatically backup over time and from several servers while just HTTP access is possible. Now I have a code where I check whether I can get a response from server in a reasonable time (accessibility check). I want this done for all html pages I specify in file. I got a foreach loop that does it. But that just don't work and asks only first item of an array. If i copy-paste the same foreach code second time, the firs loop works a expected while second again asks just the first item of the array. Here the code. Please help.
#!/usr/bin/perl use strict; use Switch; my $i; my $arguments; my $date; my $curla; my @args; my @links; my $response; my $part; my $curlc; my $time; sub check_link($) { my $link=$_[0]; my $page="NOK"; $link =~ s/\n//g; $link =~ s/\r//g; print LOG "check_link: checking validity of $link\n"; my $curlc="curl ".$curla." ".$link."\n"; print LOG "check_link: getting page with $curlc"; local $SIG{ALRM} = sub { print LOG "check_link: no response - timing out\n"; `pkill -9 -f $link`; $page="NOK"; }; alarm(10000); $page=`$curlc`; alarm(0); print LOG "check_link: got response in time\n"; return $page; } open (LOG,">>rapget.log") or die "can't open logfile\n"; $date=`date`; print LOG "$$: ============================\nnew start of script : $da +te\n"; foreach $i(@ARGV){ if($i=~/-/){$arguments.=$i." "}; if($i!~/-/){$arguments.=$i."%"}; } print LOG "$$:ARGUMENTS : $arguments\n"; @args= split (/%/,$arguments); foreach $i(@args){ switch ($i) { case /-U.*/ {print LOG "Adding user to curl\n";$curla. +=$i." ";} case /-x.*/ {print LOG "Using proxy for curl\n";$curla +.=$i." ";} else {print LOG "Unknown argument: $i\n"} } } print LOG "$$:curla=$curla\n"; open (IN,"<linklist.txt") or die "no input file found\n"; @links=<IN>; close(IN); my $link; foreach $link(@links) { chomp($link); $response=check_link("$link"); $part = $response; $part =~ s/\r//g; $part =~ s/\n//g; print "1 Empty run\n"; }

In reply to foreach problem by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.