On 7/14/98 at 8:30 AM, w e b s l a v e <PPRODOEHL@qgraph.com> wrote: > >I'm trying to check if a file exists, and if it does, increment the name >and create a new one. > >So if the file 07141998.html exists, I want to create 07141998_1.html >(of course I need to check if _that_ exists first...) > >I'm reading it a directory and then looping thru it, I'm just >stuck on the recursive part - terrible mental block today, >can anyone help me out? > This'll work, put the numeral in the right place, and actually compensate for my not reading the File::Basename pod all the way through (I had already sent a reply to Pete, then I looked over the code afterwards, and realized I'd made a mistake in the example): #!perl use strict; use File::Basename; my $i = 1; my $newfile; my $filename = "harddisk:desktop folder:example.html"; fileparse_set_fs_type("MacOS"); my ($base, $path, $suffix) = fileparse($filename, qw(.html)); do { $newfile = "$path:${base}_" . $i++ . "$suffix"; } while(-e $newfile); I did notice that the pod says you need to call fileparse_set_fs_type as above or it'll default to Unix pathsep syntax, yet the code above runs fine with or without it. >tia > > >Pete j -- #!/usr/bin/perl $dot="\x2e";$lt="\x3c";$gt="\x3e";$at="\x40"; print "J Mignault ${lt}mignault${at}nytimes${dot}com${gt}\n"; $quote = qq("They'll get my perl when they pry it from my cold, dead /usr/local/bin." --Randy Futor in <1992Sep13.175035.5623\@tc.fluke.COM>); ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch