[comp.lang.perl] Extreme novice seeks help with first perl program!

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/06/90)

In article <132794@pyramid.pyramid.com> mfrost@pyrnova.pyramid.com (Mark Frost) writes:
: I'm trying to write a perl script that goes through the password file, reads
: all the users on a given partition and deterimines their home directory,
: user id, and group id. It should then go to their home directory and set
: owner and group for all the files under that user's home directory. I'm
: to the point where I need to get a list of all files under that directory.
: What I'm trying to use is something like "find ~mfrost -print" and feed the
: output of that into an array that I can loop through with "chown".
: 
: I have 2 problems here. First is that I don't seem to be able to send the
: output of an "exec" or "eval" (I'm a bit confused about the distinction there
: as it might apply to find) to a perl variable/array.

Typically you'd open a pipe:  open(FIND,"find ... -print |").  Then
you can read the input a line at a time with <FIND>.  exec executes programs
but only by replacing the current program, so you'll never get control back.
eval has nothing to do with executing other programs--it only executes
a string as Perl code.

: Secondly, to use the
: "find" command shown above, I need to run "find" under the c-shell to 
: correctly parse ~mfrost into an absolute directory name. I've tried calling
: something like
: 
: exec("/bin/csh find ~mfrost -print");
: 
: but perl doesn't seem to like that for some reason.

Apart from the fact that exec knocks you out of the current process, you
want to say "/bin/csh -fc 'find ~mfrost -print'".  Otherwise csh is going
to try to open a script called "find", and won't succeed.

But there's no point in using csh just to get the ~mfrost notation--after
all, you just said you got the home directory from the password file.  Use
that.

And if you're on a Pyramid,

    system "bsd chown -R $owner.$group $home"

should be close to what you want, given that the variables are set up right.

Larry