in reply to unique filename
$name = ..... # whatever my $i= ''; --$i while (-e $name . $i); $name.= $i;
Of course this will give you -1 instead of _1.
Did you notice that your "_1" is appended to the ".html"? You don't get 07141998_1.html but 07141998.html_1. For demonstration purposes, mine isn't better here.
A fix could be TMTOWTDI:
my $check= $name; $check=~ s#(\.[^./]*)$##; my $ext= $1 || ''; my $i= ''; --$i while (-e $check . $i . $ext); $name= $check . $i . $ext;
|
|---|