in reply to Newbie Question -- Changing File Path?
What about something simple? Simply tell the user that
if the first command line arguement is a directory, all
the listed files will be assumed to be in that directory.
You could do something like this:
I would also warn you against using unlink the way you are. Very, very, very bad things can happen if you unlink a directory that has files in it. I would prefer to loop through the array and do them one-by-one:my @arr; if ( -d $ARGV[0] ) { my $dir = shift @ARGV; @arr = map { "$dir/$_" } @ARGV; } else { @arr = @ARGV; }
mikfirefor ( @arr ) { if ( -d $_ ) { print "nice try - I cannot unlink directories\n"; next; } unlink $_; }
|
---|
Replies are listed 'Best First'. | |
---|---|
(ichimunki) Re: Newbie Question -- Changing File Path?
by ichimunki (Priest) on Jun 25, 2001 at 20:12 UTC | |
by mikfire (Deacon) on Jun 25, 2001 at 20:43 UTC |
In Section
Seekers of Perl Wisdom