Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Newbie Question -- Changing File Path?

by mikfire (Deacon)
on Jun 25, 2001 at 19:59 UTC ( [id://91322]=note: print w/replies, xml ) Need Help??


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:

my @arr; if ( -d $ARGV[0] ) { my $dir = shift @ARGV; @arr = map { "$dir/$_" } @ARGV; } else { @arr = @ARGV; }
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:
for ( @arr ) { if ( -d $_ ) { print "nice try - I cannot unlink directories\n"; next; } unlink $_; }
mikfire

Replies are listed 'Best First'.
(ichimunki) Re: Newbie Question -- Changing File Path?
by ichimunki (Priest) on Jun 25, 2001 at 20:12 UTC
    What kind of bad things happen if I delete a directory with files in it? I'd normally just test it, but now I'm afraid. And if it's a potentially serious issue, why does Perl let you do it? Even the shell command doesn't let you delete a non-empty directory...
      Hmmm, I decided to read the docs just to make sure I knew what I was talking about. And unlink will not touch a directory unless you are root and running with the -U flag. So, it would appear that you can ignore my warning and I really didn't know what I was talking about :)

      mikfire

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://91322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2025-06-19 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.