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.


In reply to Downloading a range of sequential files by Ionizor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.