http://www.perlmonks.org?node_id=285690

This is a rework of an older script I made which did the same, but was really nasty and I doubt that this is any better *grin* Anyways it grabs the current APOD and outputs it to the cwd of where you called the script. It dates the output file as: apod(yyyy)(mm)(dd), where yyyy,mm,dd is the month day year respectively, and no the parenthesis aren't in the filename.

Edit: Changed the date format from month,day,year to year,month,day to make sorting alot easier.
Pointed out by sauoq

Edit2: Updated URI, added png.

#!/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;