in reply to system or perl function ?

It depends :)

In your case, the external program does exactly what you want, and you'd need more perl code to get the job done. So calling /bin/chown is fine.

(BTW, you should probably hardcode the path to chown in your call, in case your path gets messed up, or someone has the chance to drop a hostile executable script named chown upstream of /bin in your path, for instance. I don't know what context this script runs in.)

However, keep in mind that your script now depends on /bin/chown. I admit it's unlikely that the interface to chown will change, but it's something to keep in mind if you call external programs.

Obviously, if you'd had to chown only certain files, then using the "perl perl" approach along with the File::Find module would probably be a better choice.
--
Mike

Replies are listed 'Best First'.
Re: Re: system or perl function ?
by Kanji (Parson) on Mar 28, 2002 at 13:09 UTC
    ...and you'd need more perl code to get the job done.

    While it may take more code, using more doesn't have to involve a significant bloat (well, not visually ;)).

    use File::Find qw/ find /; my $uid = getpwnam($uname) or die "$uname: no such user"; my $gid = getpwnam($gname) or die "$gname: no such group"; find( sub { chown $uid, $gid => $_ }, @directories );

    Not bad for the added portability.

        --k.