[me@ptmr]/home/me$ perl -le 'print -2 ** 4 ' # ** binds before -
-16
[me@ptmr]/home/me$ perl -le 'print (-2) ** 4 ' # this puzzled me
-2
[me@ptmr]/home/me$ perl -le 'print ((-2) ** 4)' # parenthesis force wh
+at I want
16
but I guess print is handling the second case as a list followed by some irrelevance, do I have that about right ?
Update: Thanks Fletch now I have been enlightened! I last read perlfunc a long time ago and had not really absorbed it all at the time. Now I see the explanation print (something) something_else gives the warning print (...) interpreted as function because it looks like a function.
Cheers, R.
Pereant, qui ante nos nostra dixerunt!
| [reply] [d/l] [select] |
print is a list operator, so the second parses as (print(-2))**4 and will produce a warning if you run with -w/warnings (Useless use of exponentiation (**) in void context at -e line 1.).
Update: I mean it's not like perlfunc uses print as the example of precedence issues that can come up with list operators right in the second paragraph or anything . . .
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] [d/l] [select] |
I was taught to use a plus to disambiguate:
print +( ... )
is that no longer accepted?
| [reply] [d/l] |
I was taught to use a plus to disambiguate: print +( ... ) is that no longer accepted?
That's still fine in Perl 5, but Perl 6 disambiguates it on the basis of the whitespace alone, which is what most newcomers seem to expect. Also, unary + actually means something in Perl 6, and wouldn't work anymore for the purpose of doing nothing. So the Perl 5 usage is deprecated in that sense. But only if you believe in Perl 6... :-)
Actually, what most people expect is for Perl to read their minds, but we've been having some trouble implementing that part, so we may put it off till Perl 7.
| [reply] |
Actually, what most people expect is for Perl to read their minds
Well. A Real Gift. Actually, what Perl expects from most people is reading the minds of its developers.
Wow. This has been blunt. I don't mean it that way...
Going from low-level Perl (a.k.a Baby-Perl) to Sindarin Perl is a steady learning curve, along which one experiences many pitfalls, reasonable and questionable defaults, and really weird but useful things, and it is most helpful to get acquainted with Perl's history to understand why things in Perl are as they are. Practice sharpens the understanding, there's always something new to explore and find, at every corner are the thoughts, not only of you, but many, forged into code, at times long forgotten. Understanding Perl is in great part understanding its history, its whences and whys: it is reading the mind of its developers, and much wisdom can come thereof.
Going from Perl 5 to Perl 6 is like moving from Sindarin to Quenya. In the Sindarin world, that's the high-level language spoken by those who have been in the blessed realm of Valinor, and came back to Middle-Earth.
But we Grey-Elves haven't been there, and we are not Baby-Perl-Speakers any more. We know Valinor's lore by third hand, from Tales of Apocalypses and Synopses, and so we will have to read your minds to somehow keep our language fluent and our expressions unambiguous, and mixing Sindarin with Quenya will lead to trouble... that seems to be the biggest obstacle for transition.
The Grey-Elves did choose not to leave the lands where they awoke and saw the stars..
| [reply] |
All this makes me think I'm going to have to re-learn perl or stick with Ruby. :(
| [reply] |
| [reply] |