There are a couple ways you can go with this, depending on what you want to do.
First, you can make your script search every folder under it's starting directory. You don't specify anything on the command line.
use File::Spec::Functions qw(catfile);
my @users = glob( '/Users/*' );
foreach my $user ( @users ) { # $user looks like /Users/Buster
my $calendar_dir = catfile( $user, 'Calendar', '#msgs' );
...
}
You could also use opendir to get the list of users so you get back one directory at a time:
opendir my $dh, '/Users' or die ...;
while( my $user = readdir $dh ) {
next if $user =~ /^\.\.?\z/; # and anything else you want to skip
... # do the cool stuff
}
Second, you can make it search selected folders. Suppose that you are in your home directory. To kill the duplicates for the particular users, you'd call your script with those user's names:
dups.pl --killdups Buster Mimi Roscoe
To go through all users, maybe something like this (it almost looks like you are on MacOS X, but not quite, so I'm not sure which path you need), using a command-line glob:
dups.pl --killdups /Users/*
The solution looks similar, but you take the users from @ARGV
instead of using a glob:
foreach my $user ( @ARGV ) {
...
}
That should be enough to get you started. You'll have to integrate this with the rest of your script and fix up the paths in each case to be what you need, but that's just simple string manipulation (or even simpler than that with File::Spec.