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"], ]

In reply to Re^2: generating unique filenames (next letter in list) by Anonymous Monk
in thread generating unique filenames by Aldebaran

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.