#!/usr/bin/perl use strict; use warnings; use URI::URL; use LWP::Simple qw/get/; my $TOP = "http://apod.nasa.gov/apod/"; my $IMGPATH = 'image/\d{4}/\w+.(gif|jpg|jpeg|png)'; my @timearray = gmtime(); my $time = sprintf "%04d%02d%02d", ($timearray[5]+1900), ($timearray[4]+1), ($timearray[3]); my $content = get $TOP or die "Cannot get APOD Page\n"; my ($imgurl) = $content =~ m!($IMGPATH)!i; $imgurl = url($imgurl,$TOP)->abs; my $picture = get $imgurl or die "Cannot grab image: $!\n"; open(OUT, ">apod$time\.$2") or die "Cannot write to file: $!\n"; binmode(OUT); print OUT $picture; close OUT;