On Wed, Feb 13, 2002 at 05:20:38PM -0500, zentara wrote:
> Ok, I can understand that because  33088 = oct(100500)
> but given the octal number 33088 what function do I use
> to convert it to 100500? In other words what is the
> procedure to do octal to decimal conversion? 

You have it backwards.  Octal 100500 is 33088 in decimal.  You just did the
conversion with the oct operator.

 
> Also, I thought that the 0500 style of given file permissions
> IS octal. 

It is.


> So the docs tell me to do a chmod like this with octal values:
> chmod 0500, file

Which works.


> but in my program I'm using 33088 as the octal value?

No, you're using 33088 as the decimal value.  chmod takes two or more
arguments; the numerical mode, and a list of files.  The number can be in
any representation you like.  In the case of chmod(0500, $file) it's in
octal, in the case of chmod(320, $file) it's in decimal.  The two numbers,
0500 and 320, are equivalent representations of the same numbers, they're
just in different bases.


> futher confusing the issue for me is that
> oct(0500) = 208 
> 8 is not supposed to be in the octal digit set of 0 to 7?

You're confused about what oct does; it returns the decimal representation
of an octal value.  Also, Perl is going to trip you up here; the decimal
equivalent of 0500 is 320, not 208; Perl is converting 0500 to decimal,
passing that to oct, and then oct is converting that to decimal again.  So,
basically, oct(320) == 208.

oct is usually used for converting string values to decimal values; it's for
interpreting numbers in a different base.  For example, say your program
takes an octal mode as an argument; if it were to use this mode directly,
chmod($ARGV[0], $file), $ARGV[0] would be interpreted in a decimal base,
giving a file the permissions -rwxrw-r-- (decimal 500 is octal 0764) when
the user intended -r-x------ (octal 0500).

Please see perldoc -f oct.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to