Приглашаем посетить
Бианки (bianki.lit-info.ru)

Section 12.12.  Changing Ownership

Previous
Table of Contents
Next

12.12. Changing Ownership

If the operating system permits it, you may change the ownership and group membership of a list of files with the chown function. The user and group are changed simultaneously, and both have to be the numeric user-ID and group-ID values. For example:

    my $user = 1004;
    my $group = 100;
    chown $user, $group, glob "*.o";

What if you have a username like merlyn instead of the number? Call the getpwnam function to translate the name into a number, and the corresponding getgrnam[Section 12.12.  Changing Ownership] to translate the group name into its number:

[Section 12.12.  Changing Ownership] These two are among the ugliest function names known to mankind. But don't blame Larry for them; he's giving them the same names the folks at Berkeley did.

    defined(my $user = getpwnam "merlyn") or die "bad user";
    defined(my $group = getgrnam "users") or die "bad group";
    chown $user, $group, glob "/home/merlyn/*";

The defined function verifies the return value is not undef, which will be returned if the requested user or group is invalid.

The chown function returns the number of files affected, and it sets $! on error.

    Previous
    Table of Contents
    Next