I stopped improving nixtFile after seeing the results (the rules I don't get)
#!/usr/bin/perl --
##
##
##
## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce
+-nibc -i=4 -pt=0 "-nsak=*"
## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr
+-ce -nibc -i=4 -pt=0 "-nsak=*"
## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr
+ -opr -ce -nibc -i=4 -pt=0 "-nsak=*"
#!/usr/bin/perl --
use strict;
use warnings;
use Data::Dump qw/ dd /;
exit newTest();
sub newTest {
my @list;
my @filenames = qw/a.png dpq.jpg zx.png ott.jpg zzz.tiff oi.png/;
for my $curr ( @filenames ) {
#~ my $next = next_file( $curr );
#~ my $nixt = nixtFile( $curr );
my $next = next_file( "$curr" );
my $nixt = nixtFile( "$curr" );
my $eq = int( $next eq $nixt );
dd( [ $curr, $eq, $next, $nixt ] );
push @list, [ $curr, $eq, $next, $nixt ];
}
dd( \@list );
} ## end sub newTest
sub nixtFile {
my( $word ) = shift;
my( $file, $ext ) = $word =~ m{(.+?)(\.[^.]+)?$};
#~ dd( $file, $ext );
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/;
my %next = map {
my $ix = ( $_ + 1 ) % @alphabet;
@alphabet[ $_, $ix ];
} 0 .. $#alphabet;
#~ die dd( \%next );
my $newfile = '';
for my $char ( split //, $file ) {
#~ my $newchar = $next{$char} || 'FUDGE';
my $newchar = $next{$char} || $char;
$newfile .= $newchar;
}
return $newfile . $ext;
} ## end sub nixtFile
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;
}
}
__END__
word is a
["a.png", 1, "b.png", "b.png"]
word is dpq
["dpq.jpg", 0, "epq.jpg", "eqr.jpg"]
word is zx
it was a z
["zx.png", 0, "zy.png", "ay.png"]
word is ott
["ott.jpg", 0, "out.jpg", "ouu.jpg"]
word is zzz
it was a z
it was a z
it was a z
number of zees was 3
["zzz.tiff", 0, "aaaa.tiff", "aaa.tiff"]
word is oi
snakeeyes: you hit nothing with oi
["oi.png", 0, "a.png", "oi.png"]
[
["a.png", 1, "b.png", "b.png"],
["dpq.jpg", 0, "epq.jpg", "eqr.jpg"],
["zx.png", 0, "zy.png", "ay.png"],
["ott.jpg", 0, "out.jpg", "ouu.jpg"],
["zzz.tiff", 0, "aaaa.tiff", "aaa.tiff"],
["oi.png", 0, "a.png", "oi.png"],
]