Hello Datz_cozee75,
Here are some observations on coding style:
The calling code can be reduced from 4 lines to 2:
printf "next is %s\n", next_file($_) for qw( a.png dpq.jpg zx.png ott.jpg zzz.tiff oi.png );
sub next_file { ... 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/;
creates and populates a new @alphabet on each call to sub next_file. Here is one way to avoid this:
{ my @alphabet; BEGIN { @alphabet = ('a' .. 'h', 'j', 'k', 'm', 'n', 'p' .. 'z'); +} sub next_file { ... } }
(You could also use state, but as state variables can only be scalars, the variable would have to be an array reference, and you would then incur the additional overhead of a dereference on each access.)
$previous =~ /(.*)\.(.*)/; my $word = $1; my $ext = $2;
may be written more succinctly as:
my ($word, $ext) = $previous =~ /(.*)\.(.*)/;
$z = $z + 1; may be written more succinctly as ++$z;
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: generating unique filenames
by Athanasius
in thread generating unique filenames
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |