What is switches supposed to contain beyond the particular group of numbers it should split upon? Anyhow, this will be messy:

#!/usr/bin/perl -wl use Data::Dumper 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}]; # how many $filesplit{digit} can we find before this sucker? my $splits = 2 + grep($_ eq $filesplit{digit},@digits[0..$switches-> +{numindex}-1]); my @temp = split (/$filesplit{digit}/, $filename, $splits); $filesplit{suffix} = pop(@temp); $filesplit{prefix} = join $filesplit{digit}, @temp; return \%filesplit; } print Dumper(get_split("01-file01.html",{numindex=>1})); print Dumper(get_split("01-file01and01.html",{numindex=>1})); print Dumper(get_split("02-file01tom34bill01.html",{numindex=>3})); __DATA__ $VAR1 = { 'digit' => '01', 'suffix' => '.html', 'prefix' => '01-file' }; $VAR1 = { 'digit' => '01', 'suffix' => 'and01.html', 'prefix' => '01-file' }; $VAR1 = { 'digit' => '01', 'suffix' => '.html', 'prefix' => '02-file01tom34bill' };

That is some ugly code. Hope this helps.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1


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