Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach problem
by ikegami (Patriarch) on Aug 27, 2008 at 21:12 UTC | |
|
Re: foreach problem
by grinder (Bishop) on Aug 27, 2008 at 21:15 UTC | |
|
Re: foreach problem
by JadeNB (Chaplain) on Aug 27, 2008 at 21:10 UTC | |
|
Re: foreach problem
by toolic (Bishop) on Aug 27, 2008 at 21:08 UTC | |
|
Re: foreach problem
by Perlbotics (Archbishop) on Aug 27, 2008 at 21:18 UTC | |
|
Re: foreach problem
by Anonymous Monk on Aug 28, 2008 at 06:44 UTC |