plural and singular syntax in Perl5, PHP and Perl6

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, fellow perlers

Before posting this I spent some time googling the web at large as well as =
searching this group's archive for posts related to the idea I wish to expr=
ess, and, on cursory search, have not found any post, to date, which expres=
ses the following -- assertively and emphatically.  Yet, I feel (I compute)=
, it DOES need to be said, emphatically:

I absolutely, unequivocally LOVE, support and herald (as in, "Hats off to L=
arry Wall's genius") the syntactical distinction Perl5 (and older) makes be=
tween SINGULARITY and MULTIPLICITY.  Syntactically, per se.  In other words=
, EXPLICITLY, by means of two distinct symbols ("$" and "@").  The addition=
al syntax that deals with the INTERPLAY between singular and multiple is eq=
ually brilliant:



(the pre-pended symbols instantly signal (to the human reader) whether we a=
re dealing with a multiplicity version of 'array' or just one of its elemen=
ts (which is a scalar))

The brilliant play with "@" (plural) and "$" (singular) continues (in terms=
 of language design), with:


and then, the whopper:

@hash or @hash{qw(yada dooba boom}}

and then the enormously convenient (and code-economical) flexibility of nes=
ting all of the above in a gazillion ways:


@hash_one{keys %hash_two}

etc, etc, etc!


So, the converse of my exuberance over this syntactical excellence of Perl5=
 (as I assess it to be) is my complete bewilderment and puzzlement (putting=
 it mildly) over PHP's LACK of such distinction (syntactically) between sin=
gularity and multiplicity.

in PHP,=20




I believe (correct me if I'm wrong) that in PHP I am left guessing, by cont=
ext, whether I'm looking at a scalar or an array.

So, I can only bash my head against the wall (note: LOWER-case "wall"), ove=
r the notion that not only does PHP's shortcoming (the lack of such succinc=
t syntactical acrobatics as I've tried to suggest above, with the nested ar=
rays and hashes in Perl) has gone COMPLETELY unnoticed (ignored/forgiven/ev=
en embraced as solid standard!?), I have learned (again, please correct me =
if I am wrong) that Perl itself (!!!) -- in its new and radically revised V=
ERSION 6, is tossing out this baby with the bath water -- this gem of a syn=
tax, obliterating the "$" versus "@" distinction, and (as I would put it) i=
s descending to the painfully banal and ambiguous "$" for both scalars and =
arrays (?!) (that we observe in PHP)

I would also like to add that "singular versus plural" (one versus many) is=
 unequivocally a FUNDAMENTAL dichotomy, NOT JUST in computer programming, b=
ut in human (natural) language and human psychology and logical processing/=
thinking.  (Perhaps on a par with "zero versus one",  or "existing versus n=
on-existing", etc., but just as fundamental)

The syntactical differentiation has given us clarity and absence of ambigui=

So there, I've said it.  I hope it did NOT come across as a rant, but more =
as a rallying cry... at least a rallying to acknowledge the value of the "$=
" and "@" syntax and the fact that losing it would mean losing a whole lot =
of clever, succinct, and quintessentially Perl coding freedom and flexibili=

Re: plural and singular syntax in Perl5, PHP and Perl6

* Andrew wrote in comp.lang.perl.misc:
Quoted text here. Click to load it

  Note that the sigil for fetching a single element has changed from
  $ to @; perhaps a better way to think of it is that the sigil of a
  variable is now a part of its name, so it never changes in
  subscripting. This also applies to hashes.

So the situation is not quite as you put it.
Björn Höhrmann · ·
Am Badedeich 7 · Telefon: +49(0)160/4415681 ·
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 ·

Re: plural and singular syntax in Perl5, PHP and Perl6

Quoted text here. Click to load it


Quoted text here. Click to load it

Eh ... sorry, but it is exactly as he puts it: The original idea that
$ is roughly the same as a 'singular article' while @ is a plural one,
has been replaced by the more 'conventional' ('conventional' here
supposed to mean 'more like what other language designers also did'
and absolutely not 'conventional' as 'what people usually do' since
'people' usually don't) concept that namespaces of differently-typed
variables are separate (I don't really have an opinion in favor of one
versus the other approach[*]).
[*] OTOH, Perl6 is about throwing away the baby (who would want an
ugly kid like that, anyway) while trying to keep the bathwater (can't
OUR [ugly] kid become just as popular with the help of something like
'also deemed to be useful by superficial association'?).

Re: plural and singular syntax in Perl5, PHP and Perl6

Quoted text here. Click to load it

Every time someone says "I don't believe in theories, another theory
dies. From the traffic in CLP, it appears that real people *don't*
find the Perl 5 use of sigils to be intuitive, and don't think of the
sigils as articles. Personally, I consider sigils to be a blemish on
both Perl 5 and Perl 6.

I regard Perl a a programming language; those who regard it as a shell
may be happier with the sigils than I am.

Shmuel (Seymour J.) Metz, SysProg and JOAT  <

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to

Re: plural and singular syntax in Perl5, PHP and Perl6

On Sat, 05 Jan 2013 19:37:42 -0500 in comp.lang.perl.misc, Shmuel
Quoted text here. Click to load it

A big part is the fault of the tutorials/books.  

They will say something like a simple variable has a $ in front and
an array has @.  Then comes $foos[$i];  foos is an array, so where
is its @ sign?  It's often a long wait for a clear answer to that.

Re: plural and singular syntax in Perl5, PHP and Perl6

On Sun, 13 Jan 2013 20:44:45 -0800, David Harmon wrote:

Quoted text here. Click to load it

And then there is this, which is much more clear and understandable:



bless $bar, $God;


Re: plural and singular syntax in Perl5, PHP and Perl6

On Tuesday, January 15, 2013 5:38:37 PM UTC-5, Mladen Gogala wrote:
Quoted text here. Click to load it

That is precisely the syntactic/semantic "algorithm" (if you will) of "%" a=
nd "@" !

The sigil "%" is used to refer to associative array container as a whole, b=
ut a  "$" prepended to the same variable name instead, with curly braces as=
 subscript, is one, singular reference (to a singular or plural value)

The sigil "@" (without its subscript, square bracket [....]) is, similarly,=
 used to refer the entire array, but with the "$" instead of "@" one gets a=
 reference to a singular (scalar) value of that array.
Thus, both the associative array and the list, in Perl5, are each a syntact=
ical/semantic SET.  A set of (two) symbols, working together: [ "%" and "$"=
 ], and [ "@" and "$" ].  So, "%" shouldn't be seen as fixed and permanent,=
 but one working in conjunction with "$", which syntactically replaces it w=
henever a singularity it contains is referred to.=20

With the associative array, you actually have A SET of (all) THREE sigils w=
orking together semantically/syntactically ( [ "%", "$", and "@" ] ):=20

%pets=3Dqw(John dog Jane cat Bobby gerbil Laura monkey Mike cobra Betty fal=
con Sally dog Sheila rabbit Chuck dog Jeremy horse);

print join(', ', @pets{qw(Bobby Betty Jane)}), "\n";


@slackers=3Dqw(Mike Bobby Laura Sheila);

print join(', ', @pets), "\n";

or, using plural subscripting for both hash and array, one nested in the ot=

print "The pets of the first and last slackers: ",  join(', ', @pets{@slack=
ers[0,$#slackers]}), "\n";

It seems to me that the above is brilliant language design, which allows fo=
r efficient (economical), beautiful code.

And my examples are just the surface of all that's possible, in terms of th=
e  coding power this interplay between the (distinct) plural and singular s=
yntax grants. (Again: when you get to multi-dimensional arrays, multi-dimen=
sional hashes and multi-dimensional array/hash hybrids, this sigil interpla=
y in Perl5 is INVALUABLE, and probably unrivaled by any other language out =
there! (correct me if I'm wrong))

Also, again, conceptually, the notion of "singular" versus "plural" is FUND=
AMENTAL to human psychology and reason.  It is healthy and profitable to me=
ticulously address and sort out logic related to it.  This Perl syntax FORC=
ES one to fully wrap one's mind around what's going on, conceptually... whi=
ch is a good thing, in the end.

Site Timeline