Cy Kurtz wrote:
> I hope it's an easy one for you. It's not quite easy enough for me.
>
> I want to harvest some files from a website. The files are in this
> format:
>
> fooYYMMDD.ext, as in foo030901.ext for September 1st, 2003.
>
> To wget the first nine months of this daily file, I need a file that
> looks like this:
>
> http://basic.url/dir/foo030101.ext
> http://basic.url/dir/foo030102.ext
> http://basic.url/dir/foo030103.ext
> .
> .
> http://basic.url/dir/foo030901.ext
>
> I'm too lazy to type all of this, so I'm trying to use this little
> script to generate the file for me. It keeps tripping over the last
> close bracket. Can you tell me what I'm doing wrong here?
>
> Thanks,
>
> Cy Kurtz
>
> Here's my script:
>
>  #!/usr/bin/env perl
>  #
>  open OUTFILE, ">output.txt" or die "Can't open output.txt: $!";
>   while($month < 9)
>   {
>   while($day < 31)
> {
> print OUTFILE "http://basic.url/dir/file03,$month,$day,.ext,\n";;
>         continue
> $day++;
> }
> continue
> $month++;
> }

There's a few things wrong with your code:

- The 'continue' needs a code block following it, but you don't need
it anyway.

- You're not initialising $day and $month, so the first time around
'print' will try to print a value of 'undef'.

- you don't need the commas embedded in your output string.

- You're not printing leading zeroes on values less than 10.

- Most important of all, you don't start with

  use strict;
  use warnings;

The code below will do what you want.

HTH,

Rob


use strict;
use warnings;

open OUTFILE, '> output.txt' or die $!;

for my $month (1 .. 9) {
  for my $day (1 .. 31) {
    printf OUTFILE "http://basic.url/dir/file03%02d%02d.ext\n";, $month, $day;
  }
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to