Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Edited by Corion: Added <CODE> tags
This is lifted from the perlsyn documentation. I'd like to know if O_RDONLY is being passed, but since O_RDONLY == 0 the first conditional fails.Is there an idiomatic version of this test? is it just not done?
== code == use warnings; use strict; use Fcntl; my $flag = O_RDONLY; my $amode = do { if ($flag & O_RDONLY) { "r" } # XXX: isn't th +is 0? elsif ($flag & O_WRONLY) { ($flag & O_APPEND) ? "a" : +"w" } elsif ($flag & O_RDWR) { if ($flag & O_CREAT) { "w+" } else { ($flag & O_APPEND) ? "a+" : + "r+" } } }; print "$amode\n"; # Prints "0" for O_RDONLY
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing for O_RDONLY
by I0 (Priest) on Feb 01, 2001 at 00:28 UTC | |
by Anonymous Monk on Feb 01, 2001 at 00:40 UTC |