Ionizor has asked for the wisdom of the Perl Monks concerning the following question:
I've written up this little script that will print a range of sequential URLs based on an input URL. The idea is to generate a list of files suitable for use with wget. I was just wondering if there were any obvious improvements I could make to the regexes I'm using to extract the pathnames (or a module to eliminate them entirely) or just general improvements that could be made to the script.
Any help is much appreciated. Thanks.
#!/usr/bin/perl require 5.6.1; use strict; use warnings; die "Usage: listseq.pl <url> [min] <max>\n" unless (@ARGV >= 2 and @AR +GV <= 3); # Retrieve the URL my $extract = shift; # Sort out the range of numbered files we should be getting my $min; if (@ARGV >= 2) { $min = shift; } else { $min = 1; } my $max = shift; # Separate the path from the filename and save both $extract =~ /^(\S*\/)(\S*?)$/; my ($filepath, $filename) = ($1, $2); # Pull the filename and extension from the file; determine precision ( +1 vs 01) $filename =~ /^(\S+?)(\d+)(\.\S+)$/; my ($name, $numlength, $extension) = ($1, length($2), $3); # Print the list of filenames for (my $i = $min; $i <= $max; $i++) { print ($filepath, $name, (sprintf "%0${numlength}d", $i), $extension +, "\n"); }
--
Grant me the wisdom to shut my mouth when I don't know what I'm talking about.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Downloading a range of sequential files
by revdiablo (Prior) on Jul 25, 2003 at 03:03 UTC | |
by Ionizor (Pilgrim) on Aug 06, 2003 at 22:42 UTC | |
by revdiablo (Prior) on Aug 06, 2003 at 23:55 UTC | |
by Ionizor (Pilgrim) on Aug 07, 2003 at 02:04 UTC | |
|
Re: Downloading a range of sequential files
by Nkuvu (Priest) on Jul 25, 2003 at 03:23 UTC | |
|
(jeffa) Re: Downloading a range of sequential files
by jeffa (Bishop) on Jul 25, 2003 at 15:23 UTC | |
by Ionizor (Pilgrim) on Jul 25, 2003 at 21:46 UTC |