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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |