[comp.lang.perl] chmod

mmuegel@camdev.comm.mot.com (Michael S. Muegel) (02/26/91)

I have been trying to get chmod working with a non-numeric mode argument
(e.g. a scalar variable). I seems that the following:

  chmod ($Mode, $File);

does not work as expected. I think it is using the ASCII numerical values
or the like. When I do a ls -l I get bits I did not even know existed!

Now I think the answer invlolves using pack or vec, but then again, maybee
not. Can anyone enlighten me?

Thanks,
-Mike
-- 
+-----------------------------------------------------------------------------+
| Mike Muegel                              | Internet: mmuegel@mot.com        |
| Software Tools Group                     | UUCP:     uunet!motcid!muegel    |
| Fort Worth Research & Development Center | Voice:    (817) 232-6129         |
| Cellular Infrastructure Group            | Fax:      (817) 232-6081         |
| Radio Telephone and Systems Group        | Mail:     5555 North Beach St.   |
| Motorola, Inc.                           |           Fort Worth,  TX 76137  |
+-----------------------------------------------------------------------------+

tchrist@convex.COM (Tom Christiansen) (02/27/91)

From the keyboard of mmuegel@mot.com (Michael S. Muegel):
:I have been trying to get chmod working with a non-numeric mode argument
:(e.g. a scalar variable). I seems that the following:
:
:  chmod ($Mode, $File);
:
:does not work as expected. I think it is using the ASCII numerical values
:or the like. When I do a ls -l I get bits I did not even know existed!

If what's really happening is what I think is happening, consider this:

    print "mode? ";
    chop($Mode = <STDIN>);
    printf "mode is %04o\n", $Mode;
    chmod $Mode, $File;

This may clear some things up.  If your mode is not a literal, like this:

    $Mode = 0644;

then you'll have to octify it:

    $Mode = oct($Mode);


--tom
-- 
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist@convex.com      convex!tchrist