|Just another Perl shrine|
Unwanted Octal to Decimal Conversionby djantzen (Priest)
|on Feb 18, 2004 at 20:36 UTC||Need Help??|
djantzen has asked for the
wisdom of the Perl Monks concerning the following question:
I've got a module that utilizes Unix style octal permissions to regulate whether users can perform certain tasks depending on ownership and group membership criteria. Basically what I want to do is set up class constants for various permissions like:
and then use these to create masks for comparison to the actual permissions associated with the object. Unfortunately for me, perl automatically converts these into their decimal form when I really do want them to be octals, which means that to use them I have to run them through sprintf like sprintf("%o", OWNER_READ). But even that's trouble because I can't get the proper zero-padding to work so e.g., '0040' comes back '40'. This means for example, that my $mask = 40 | 400 comes back '400' while what I need is '440'.
Complicating matters is the fact that Oracle drops leading zeros in a NUMBER column so when I pull my permissions from the database I have still another conversion to do. So far, the only way I can actually get this to work is to treat it like a string in Perl e.g., use constant OTHER_READ => '0001'; and then prepend the zeros as a string when pulling it from the database, but clearly this is a nasty hack.
Thanks for any help.
"The dead do not recognize context" -- Kai, Lexx