Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: open(): Is there a simple way to map between numeric open modes and "symbol modes"?

by Anonymous Monk
on Feb 08, 2013 at 05:09 UTC ( #1017765=note: print w/ replies, xml ) Need Help??


in reply to Re^2: open(): Is there a simple way to map between numeric open modes and "symbol modes"?
in thread open(): Is there a simple way to map between numeric open modes and "symbol modes"? (solved)

See also FileHandle::Fmode and Fcntl

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use Fcntl(); my %mode2symbol = ( #~ Fcntl::F_DUPFD() => '&', Fcntl::O_RDONLY() => '<', Fcntl::O_RDWR() => '+<', Fcntl::O_TRUNC() => '>', Fcntl::O_WRONLY() => '>', Fcntl::O_APPEND() => '>>', Fcntl::O_CREAT() => '>', ); my %name2mode = ( #~ F_DUPFD => Fcntl::F_DUPFD(), O_RDONLY => Fcntl::O_RDONLY(), O_RDWR => Fcntl::O_RDWR(), O_TRUNC => Fcntl::O_TRUNC(), O_WRONLY => Fcntl::O_WRONLY(), O_APPEND => Fcntl::O_APPEND(), O_CREAT => Fcntl::O_CREAT(), ); $mode2symbol{ $name2mode{O_RDWR} | $name2mode{O_APPEND} } = '+>>'; $mode2symbol{ $name2mode{O_RDONLY} | $name2mode{O_APPEND} } = '+>>'; $mode2symbol{ $name2mode{O_WRONLY} | $name2mode{O_APPEND} } = '+>>'; dd \%mode2symbol; dd \%name2mode; __END__ { "0" => "<", "1" => ">", "2" => "+<", "8" => "+>>", "9" => "+>>", "10" => "+>>", "256" => ">", "512" => ">", } { O_APPEND => 8, O_CREAT => 256, O_RDONLY => 0, O_RDWR => 2, O_TRUNC => 512, O_WRONLY => 1, }


Comment on Re^3: open(): Is there a simple way to map between numeric open modes and "symbol modes"?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-08-30 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls