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

Inspired by Develop your own weather maps and alerts with Perl and GD, I have put together a script which downloads the base radar image from a specific site at a specified interval.
use strict; use LWP::Simple; use POSIX; my $refresh = 1800; do { my $base="http://radar.weather.gov/ridge/RadarImg/N0R/MTX_N0R_0.gi +f"; my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime() ); my $savefilename = "SLCRadar_".$timestring.".gif"; my $status = getstore($base,$savefilename); print $status."\n" ; sleep $refresh; } while ($refresh);

Replies are listed 'Best First'.
Re: Automated downloading of NOAA radar images
by merlyn (Sage) on Jun 13, 2007 at 23:28 UTC
    I don't see $refresh changing in the loop, so I'm not sure why you have a do-while $refresh. If you just want an infinite loop, a naked block with a redo at the end will do nice.
      Thanks for the tip, merlyn, I have "refactored" my code as follows:

      use strict; use LWP::Simple; use POSIX; my $refresh = 1800; { &imagegrab; sleep $refresh; redo; } sub imagegrab { my $base="http://radar.weather.gov/ridge/RadarImg/N0R/MTX_N0R_0.gi +f"; my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime() ); my $savefilename = "SLCRadar_".$timestring.".gif"; my $status = getstore($base,$savefilename); print $status."\n" ; }

      It does seem a cleaner way to handle this...
      I know it doesn't really matter in this case but generally speaking isn't a while(1) block a better choice for infinite looping? I would think performance would be the same (I assume a while block collapses down to a naked-redo block) which leaves code readability. And letting the reader know at the beginning of the block that it's an infinite loop is a lot better than forcing the reader to wade through several lines of code before discovering that. Is that a good assessment or am I missing something?