On 5/26/10 Wed May 26, 2010 2:22 PM, "Andros Zuna" <andros.z...@gmail.com> scribbled:
> Hi again, > > have a new script her, I want to create a code that will read a data > file of the following format > > <number of times> <sleep time> > > The first column describes how many times the script should download a > URL, and the second column describes how many seconds the tool should > sleep before going on... > > This is what i got this far, (I prefer to use the unix, wget command > to do this operation if posible) > > #! /usr/bin/perl You should put 'use strict;' and 'use warnings;' here. > > > $data = "file"; > $URL = "www.cnn.com"; > $c = 1; > > > open (FILE, $data) or die "Error: $!"; > > > while ($line = <FILE>){ $line has a newline at the end. chomp($line); > my @array = split /\s+/,$line; > my $exe = $array[0]; > > my $sleep = $array[1]; You can split directly into a list of variables; > > if ($c >= $exe) { A for loop would be good here. > > system('wget "$URL"'); Single quotes do not allow for variable interpolation. > $c++; > } > > sleep $sleep; Do you mean to sleep between fetches? Then sleep inside the loop. > } > > This is clearly wrong, but could anyone please tell meg how to get this scipt > Try this (untested): #!/usr/bin/perl use strict; use warnings; my $data = "file"; my $URL = "www.cnn.com"; open (my $fh, '<', $data) or die "Error: $!"; while ($line = <$fh>){ chomp($line); my( $c, $sleep ) = split /\s+/,$line; for ( 1 .. $c ) { system("wget $URL"); sleep $sleep; } } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/