Kevin Pfeiffer wrote:

> Hi all,
> 
> I just took another look at an exercise I wrote a couple months ago and
> fleshed it out a bit. It is a commandline "trashcan" program which I
> actually use. Instead of typing 'rm' I almost always use 'rmm' now.
> 
> It's meant to be used in a "friendly" environment, nonetheless, if anyone
> sees any potentials for error (or suggestions for better work) please say
> so...
> 

i didn't read your whole script, only the first 20 lines or so and i have a 
few suggestions:

1. you have:

if ($ARGV[0] =~ /^-(.)$/) {

can your program handle files starting with a '-'? it's legal in *nix for 
file names to begin with a '-':

[panda]$ touch ./-abcd
[panda]$ ls -l ./-abcd
-rw-r--r--    1 dzhuo     dzhuo            0 Oct 24 16:13 ./-abcd
[panda]$ rm -f ./-abcd

i understand that you can still supply files to rmm starting with '-' like:

[panda]$ rmm ./-remove-this-file
[panda]$ rmm /home/dzhuo/-remove-this-file

but i think it's still nice (maybe) to be able to just:

[panda]$ rmm -remove-this-file

2. you have:

($trash_dir) or die "Error: No trash directory defined!\n";

which means you will not allow user to name his/her trash directory '0'? for 
a general utility program like your rmm, you should relax this restriction.
btw, $trash_dir is hard coded in your script so how can it ever be false?

3. you have:

$path =~ /.*\..+$/ or die "Name of trash directory must begin with a dot 
followed by one or more letters!\n";

your regex does not match your die message.

4. you have:

unless (-e $path) {
     print "Creating trash directory: $path\n";
     mkdir $path or die "Couldn't create $path: $!\n";
}

don't do this for a general utility program where your program might be 
involved very often from different scripts. you have a race condition. do 
something similar to the following instead:

[panda]$ perl -MErrno -e 'die $! unless(mkdir('foo') || $!{EEXIST});'
[panda]$

5. see if Getopt::Std (and friends) can help you simplify your arg parsing 
code.

6. see if Fild::Find can help you simplify some of your dir scanning code.

7. it will be nice to set a limit on how big your trash dir can be. 
otherwise, it's easy for people to give putting stuff into it and forget 
about how big it has grown to.

if i have time, i will check the whole script for you.

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,

goto=>print+eval

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to