#!/usr/bin/perl
use strict;
use LWP::Simple 'getstore';

# squidfingers.pl - will willis - 05/28/2008
# a script to download groovy background images like:
# http://squidfingers.com/assets/patterns/pattern_028.gif

my $count   = 1; # to iterate over images
my $error   = 0; # count failed requests
my $give_up = 5; # when we've probably run out of images

while (1) {
    download_bg($count) || $error++;
    last if $error > $give_up;
    $count++;
}

sub download_bg {
    my $num = sprintf("%03d",shift);
    my $url = "http://squidfingers.com/assets/patterns/pattern_$num.gif";
    my $response = getstore($url,"$num.gif");
    return ($response eq '200') ? 1 : 0;
}