develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl feature wish: quote-word array-ref operator

Thread Previous | Thread Next
From:
=?UTF-8?Q?Andr=c3=a9_Warnier_=28tomcat/perl=29?=
Date:
March 11, 2021 10:13
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
316d8959-bdb6-6bab-ca2c-ff9b3e5ffb25@ice-sa.com
On 11.03.2021 09:29, Alexander Hartmaier wrote:
[...]
> What I hate about quoting in Perl in general is that it doesn't allow to use the dash! my 
> %hash = ( foo-bar => 'baz' ); doesn't work and needs to be quoted.

The fact that
%hash = ( foobar => 'baz' );
works, and automatically quotes the key (*), is "perl syntactic sugar":  it's nice because 
it saves some tedious typing sometimes, and it is in the (historical) spirit of perl (**).
(And perl programmers being the feisty guys they are, it's probably used in thousands of 
programs and modules by now).

But in my opinion, it is also one of these things which make the language nowadays get 
this reputation for being rather "less rigorous" than others (***).  In all other 
languages that I know of, you would *always* need to quote literal keys and values, when 
you fill a hash :

%hash = ( 'foobar' => 'baz' );

So maybe we should just lay back and enjoy the time we save in typing every time it works, 
and just remember that sometimes it doesn't and then we have to do it the hard way. And to 
re-use the time saved, we can just have a beer or a coffee.


(*) The fact that it doesn't work when the key is foo-bar, is probably due to the 
difficulty for the interpreter to distinguish this form from other things. I imagine that 
when it finds the "=>", it needs to back-track to quote the previous token. But hey, when 
it finds the "-", what should it do ?
And to correct that, you probably have to fix so many other things, that you end up with 
Raku instead of perl.

(**) "There is more than one way to do it", "laziness, hubris, etc..". For many things, 
perl allows you to be rather "sloppy" and get away with it.
But sometimes it bites..

(***) I mean, in the minds of purists and programming language theoricians.
For perl enthousiast users like me of course, it is just plain fun.

P.S.
Personally, I try to always quote the keys, even when I don't have to.
But I'm having the beer anyway.
Because I figure that I save all the times in the future when I would otherwise have to 
explain to a colleague (or to myself) what I was trying to do there.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About