Newbie Trying to learn perl

N

Nathan M.

I needed some help trying to figure out how to write a small perl
script in a Sun Solaris environment that can recursivly search through
a directory structure and get file information such as owner, size,
last modified date, permissions, things like that. I have tried to
use a File::Find but because I am very new at this I don't know where
to go from there. Thanks for any help.
 
J

Joe Smith

Nathan said:
I needed some help trying to figure out how to write a small perl
script in a Sun Solaris environment that can recursivly search through
a directory structure and get file information such as owner, size,
last modified date, permissions, things like that. I have tried to
use a File::Find but because I am very new at this I don't know where
to go from there. Thanks for any help.

Are you aware that there is a perl utility called `find2perl`?
You give it the same command line arguments as you would to `find`
and it produces a perl program that outputs the same results.

solaris% find /tmp /var/tmp -ls
solaris% find2perl /tmp /var/tmp -ls >myprog.pl
solaris% perl myprog.pl

The relevant parts are:

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/tmp', '/var/tmp');
exit;

sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
ls;
}

sub ls () {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
...
}


-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top