<?xml version="1.0" encoding="windows-1252"?>
<node id="985434" title="Re^3: state and file perms confusion" created="2012-08-04 09:55:12" updated="2012-08-04 09:55:12">
<type id="11">
note</type>
<author id="421114">
Tanktalus</author>
<data>
<field name="doctext">
&lt;p&gt;There aren't a lot of use cases for storing an octal "number" in a scalar.  There are some, but they're all to do with formatting output, not actual use as a number.&lt;/p&gt;
&lt;p&gt;If your goal is to use this for [doc://chmod], you have to realise that it won't work.  If you do this:
&lt;c&gt;
$mode = sprintf "%o", 420; # $mode = 644
chmod $mode, $file;
&lt;/c&gt;
you'll actually be doing the same thing as this:
&lt;c&gt;
chmod 01204, $file; # 01204 octal == 644 decimal
&lt;/c&gt;
Definitely not what you wanted.  Leave the number as-is if you plan on using it in chmod.  Note that the following lines are equivalent:
&lt;c&gt;
# 1. octal number
chmod 0644, $file;
# 2. decimal number
chmod 420, $file;
# 3. number in a scalar
$mode = 0644;
chmod $mode, $file;
# 4. number in a scalar (from decimal)
$mode = 420;
chmod $mode, $file;
# 5. number with bitmasks
$mode = 0666 &amp; ~022; # like umask
chmod $mode, $file;
# 6. decimal with bitmasks
$mode = 438 &amp; ~022; # 438 == 0666
chmod $mode, $file;
&lt;/c&gt;
So, to answer your question, the number is already in the scalar.  You don't actually need to do anything about it.&lt;/p&gt;
&lt;p&gt;And, if you use &lt;c&gt;$mode = sprintf "%o", $mode;&lt;/c&gt;, remember what you just did: you took a number, you printf'd it into a &lt;b&gt;s&lt;/b&gt;tring, and put that back in $mode.  So $mode no longer carries a number but a string.  Perl will try to force it back to a number if that's what you try to do, but it won't be the number you started with.&lt;/p&gt;</field>
<field name="root_node">
985371</field>
<field name="parent_node">
985373</field>
</data>
</node>
