# supersearch this one - short version: it detects most common coding
+errors.
# always use it.
use strict;
sub lsForCorp {
my $corp = $_[0];
# File::Spec allows you to create a directory structure in
# a platform-independant manner. Not a big deal to you since
# this probably only runs on unix anyway, but all my code
# has to run on both unix and Windows, so it's just a
# habit.
require File::Spec;
my $path = File::Spec->catfile(
# this reconstructs the path - if you print $path, you'll
# see exactly the path you were using - again, no big deal
# if portability is unimportant (and "/usr/local" is not
# really portable either ;->)
File::Spec->rootdir(),
qw(usr local farms * * input), "*$cor
+p*"
);
# let glob do all the work rather than ls. Besides, ls
# calls the same thing as glob under the covers, more or
# less. (Technically, it's the shell.)
my @farms = glob($path);
foreach my $farm (@farms) {
# no if statement since the glob already only gets files that match
# *$corp*, which is the glob way of saying /\Q$corp/.
print $farm, "\n";
} # end of foreach statement
} #end of lsForCorp subroutine
#------------------- End Subroutines ---------------------#
print "What corp are you looking for? " ;
# chomp it to remove the trailing newline.
chomp(my $whatWeWant = <STDIN>);
# & doesn't do what you think it does - avoid it unless you
# actually mean to do what it does.
lsForCorp($whatWeWant);
If you want to search more than just "input", you want to search all directories at that level, you just change "input" to "*", and it'll handle that: /usr/local/farms/*/*/*/*$corp*. As long as everything is at the same depth in the directory tree, this works fine. If you're looking for files at different depths, you'll need to use File::Find or something similar.
As for getting the date/time/bytecount, you'll need to use the -X functions and/or stat or File::stat. e.g.:
use File::stat;
# ...
my $s = stat($farm);
printf "%s: Age [%s], size [%d]\n", $farm, $s->mtime(), $s->size();
|