On Thu, Apr 21, 2005 at 06:40:54PM +0200, Juerd wrote:
: Larry Wall skribis 2005-04-21  8:54 (-0700):
: >     if $filename ~~ -r & -w & -x {...}
: 
: Just curious - would the following dwym?
: 
:     if (&prefix:<-r> & &prefix:<-w> & &prefix:<-x>)($filename) { ... }

It might do what you mean.  Personally, I would never mean that if I
could help it.  :-)

: > It seems to me that -e «$_» would handle most of these cases, as long as
: > whitespace always comes in quoted so that you always end up with one word.
: > That seems more general than a special option to -X ops.
: 
: Wouldn't it be a good option to combine the filetest operators into one
: operator? It'd even be historically correct to call that test:
: 
:     test(:r & :w, $fn);

Hmm.  I think this works syntactically:

    $file ~~ all(:r:w)

: I still like -r -w $fn much better than the binding and the ~~ things.

There's one minor problem with -r -w $file, which is that it evaluates
right-to-left, which is going to surprise some people who think they
want to say

    -e -r $file

when they really mean

    -r -e $file

But that doesn't really matter much unless you're so much into speed
that you think about falsifying the test without doing a stat().

Now the interesting thing about the ~~ approach is that it naturally
lends itself to

    given $file {
        when :x         {...}
        when :r:w       {...}
        when :r(0)      {...}
        when :u | :g    {...}
        default:
    }

I suppose it's a little bit rude to grab all the pairs for testing
against all the strings, so maybe we have to say

    given $file.test {...}
    $file.test ~~ :r&:w

or maybe

    given $file.stat {...}
    $file.stat ~~ :r&:w

which leaves room for lstat if we need it, though I can't say I'm fond
of the Unix naming scheme here.  If we borrow from IO::All maybe it's just:

    given io($file) {...}
    io($file) ~~ :r&:w

BTW, I'm assuming the $file is either $filename or $filehandle there.

Larry

Reply via email to