I was hoping what I was trying to accomplish would be clear without having to post all the code but apparently it's not. Here is the full code for my script, which is a rewrite of the script in this node to create a sequential list of files.

#!/usr/bin/perl require 5.8.0; use strict; use warnings; # Load in the modules we'll be using use URI; use Pod::Usage; use Getopt::Long; use File::Basename; my $switches = process_switches(); # User has goofed so be concise pod2usage( -verbose => 0) unless (@ARGV >= 1 and @ARGV <= 3); # User has asked for help so be helpful if ($switches->{help}) { pod2usage( -verbose => 1, -message => "More help: cherry.pl --man\n", -output => \*STDERR); } # User has asked for more help so be more helpful if ($switches->{man}) { pod2usage( -verbose => 2 -output => \*STDERR); } # This is our input URI my $uri = shift; # Split the URI into a host / path and filename my ($filepath, $filename) = get_file_path_name($uri); my $filesplit = get_split($filename, $switches); my ($min, $max) = set_limits(@ARGV, $filesplit->{digit}); # Use default precision if none was specified unless ($switches->{precision}) { $switches->{precision} = length($filesplit->{digit}); warn "Autodetected precision as $switches->{precision} digits.\n" if + ($switches->{verbose}); } if ($switches->{verbose}) { if ($switches->{reverse}) { warn "Generating sequence from $max to $min.\n" if ($switches->{ve +rbose}); } else { warn "Generating sequence from $min to $max.\n" if ($switches->{ve +rbose}); } } # Print out the sequential list... for (my $i = $min; $i <= $max; $i++) { # Print the path and filename prefix print $filepath.$filesplit->{prefix}; unless ($switches->{reverse}) { # ...in ascending order print (sprintf "%0$switches->{precision}d", $i); } else { # ...or in descending order print (sprintf "%0$switches->{precision}d", $max - $i + 1); } # Print the filename suffix print $filesplit->{suffix}."\n"; } sub process_switches { my %switches; # Call Getopt::Long to handle any switches that might be present GetOptions ( 'help|h|?' => \$switches{help}, 'numeric-index|n:i' => \$switches{numindex}, 'precision|p:i' => \$switches{precision}, 'reverse|r' => \$switches{reverse}, 'verbose|v' => \$switches{verbose}, ); $switches{numindex} ||= -1; return \%switches; } sub get_file_path_name { # Get the URI that's been passed to the function my $input_uri = shift; # Create a new URI object based on it my $uri = URI->new($input_uri); # Extract the filename from the URI my ($filename) = fileparse($uri->path); # Slice the filename off a copy of the URI to get the full server / +path my $filepath = $uri; $filepath =~ s/$filename//; return ($filepath, $filename); } sub set_limits { my $warn_flag = 1 if (@_ == 3); my $max = shift if (@_); my $min = shift if (@_); $min ||= 1; # Swap max and min if they're wrong if ($min > $max) { ($min, $max) = ($max, $min); warn "Waring: Given min is larger than max. Swapping values.\n" if + ($switches->{verbose}); } $min += 0; $max += 0; return ($min, $max); } sub get_split { my $filename = shift; my $switches = shift; my %filesplit; my @digits = $filename =~ /(\d+)/g or die "Error: Could not extract +a number from filename '$filename'.\n"; $filesplit{digit} = $digits[$switches->{numindex}]; ### This won't work for files like 01-file01.html ($filesplit{prefix}, $filesplit{suffix}) = split (/$filesplit{digit} +/, $filename, 2); ### This won't work for files like 01-file01.html return \%filesplit; }

--
Grant me the wisdom to shut my mouth when I don't know what I'm talking about.


In reply to Re: Specific instance of a repeated string by Ionizor
in thread Specific instance of a repeated string 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.