my @filenames = qw/a.png dpq.jpg zx.png ott.jpg zzz.tiff oi.png/;
foreach (@filenames) {
my $next = next_file($_);
say "next is $next";
}
####
sub next_file {
use strict;
use warnings;
use 5.010;
my ($previous) = shift;
my @alphabet = qw/a b c d e f g h j k m n p q r s t u v w x y z/;
$previous =~ /(.*)\.(.*)/;
my $word = $1;
my $ext = $2;
say "word is $word";
my @letters = split( //, $word );
my $z = 0;
# main control outer loop...all indexes begin with 0
foreach my $dummy ( 0 .. $#letters ) {
foreach my $index ( 0 .. $#alphabet ) {
if ( $alphabet[$index] eq $letters[$dummy] ) {
my $highest = $#alphabet;
if ( $index < $highest ) {
$letters[$dummy] = $alphabet[ $index + 1 ];
my $string = join( '', @letters, ".$ext" );
return $string;
}
else {
say "it was a $alphabet[-1]";
$z = $z + 1;
}
}
}
}
if ( $z eq ( $#letters + 1 ) ) {
say "number of zees was $z";
my $newindex = $#letters + 1;
my @newword;
foreach ( 0 .. $newindex ) {
$newword[$_] = $alphabet[0];
}
my $newstring = join( '', @newword, ".$ext" );
return $newstring;
}
else {
say "snakeeyes: you hit nothing with $word";
my $string3 = join( "", $alphabet[0], ".$ext" );
return $string3;
}
}
####
word is a
next is b.png
word is dpq
next is epq.jpg
word is zx
it was a z
next is zy.png
word is ott
next is out.jpg
word is zzz
it was a z
it was a z
it was a z
number of zees was 3
next is aaaa.tiff
word is oi
snakeeyes: you hit nothing with oi
next is a.png