Perl 5 has the qx// operator which does readpipe. I believe the function
for it was added later. (It doesn't handle a LIST as system does,
unfortunately.) qx// is also known as ``. Two backticks.

readpipe/qx/`` isn't used much. In all my @INC, only a handful of uses
can be found. Most are in Debian's modules.

Why should readpipe get to cheat on the huffman thing?

I think even qx// is too short for something that is almost never used
and is actively discouraged because interpolating values in shell
command lines is dangerous.

There is something that is used much more often than readpipe, and it
was recently made harder to type. Hash subscripts. %hash{'key'} works,
%hash<<key>> does too, but they're both a lot of typing. I never liked
typing the {} anyway, and now there is even more to type. Don't get me
started on «», which doesn't even get rendered with my current terminal
settings, and is 8 key presses in total.

In Javascript, arrays are objects, objects are arrays. The . operator is
the same one as [], except you can use an expression in [].

    parent.frames[1].document.forms['login'].elements['password'].value

equal:

    parent.frames.1.document.forms.login.elements.password.value

I like that a lot, because it saves a lot of typing and in simple cases
actually makes reading the code easier. Template Toolkit also lets you
use hashes like this.

    [% hash.key %]

However, there is an obvious clash when some bareword is both an
existing key and an existing method. I'd have to look up or try to see
what in TT [% hash.keys.5 %] does if hash.exists('keys') and it is an
array reference.

I propose to use ` as a simple hash subscriptor, as an alternative to {}
and <<>>. It would only be useable for \w+ keys or perhaps -?\w+. As
with methods, a simple "atomic" (term exists only in perlreftut, afaix,
but I don't know another word to describe a simple scalar variable)
scalar should be usable too.

    %hash{'key'}
    
    $hashref{'foo'}{'bar'}{'baz'}{'quux'}
    
    %hash{$key}

    $object.method.{'key'}

can then also be written as:

    %hash`key
    
    $hashref`foo`bar`baz`quux   
    
    %hash`$key

    $object.method`key

With some imagination, this can also be used for arrays. That would need
to allow the key to have /^-/ and it poses a problem with hybrids like
$0. Normally []/{} decides whether it's a hash or array dereference, but
for this easy-to-write thing a /^-?\d+$/ should be doable. After all, []
and {} are still available if you need to be explicit.

    $0`15     # $0[15]
    $0`alpha  # $0{'alpha'}

With even more imagination, but I still think it would be a good idea,
this can also be hijacked by the :foo pair constructor, to quote a
single simple bareword.

    key => 'value'
    
    :key('value')
    
    :key`value
    
    use Some::Module :foo :bar :baz`quux :xyzzy;

In case it was not already obvious, I'd like to stress that I'm not
proposing to use ` as something that is balanced. It's unary.

Apocalypse 2 says about the unbalanced ' in Perl 5:

    And although we're adding a properties feature into Perl 6 that is
    much like Ada's attribute feature, we won't make the mistake of
    reintroducing a syntax that drives highlighting editors nuts. We'll
    try to make different mistakes this time.

I disagree. It's not as if many editors will handle "$foo{"bar"}"
correctly out of the box. I can't even imagine a way to make that look
nice. So let's just have this autoquoting, method-ish `, please. Hashes
are used a lot in Perl and ` is in an extremely easy to type place.

It's a shame to give away that beatiful key to readpipe if you can use
it for hashes instead.

I think %hash`key makes sense. But I'd like to find out if more people
like this idea.


Juerd

Reply via email to