[$x => $y]->[$x <= $y]
Holy shit - just realized I first touched Perl 15 years ago! [$x => $y]->[$x <= $y]
Holy shit - just realized I first touched Perl 15 years ago! $x > $y ? $x : $y
in this use case, then you have way too much time on your hands.[$x => $y] creates an array reference. => is just a fancy syntax for a comma. So its actually [$x, $y].
[$x => $y]-> dereferences the array ref.
$x <= $y is a boolean expression which return 0 or 1. Accordingly the array index is chosen.
Sorry if I'm unable to explain properly! Here's a script.
#!/usr/bin/perl
use strict;
use warnings;
my $x = 8;
my $y = 9;
print [ $x => $y ]->[ $x <= $y ];- Why does the array have to be explicitly dereferenced? Isn't it obvious from context?
- Why count on the mapping from boolean to int being false = 0, true = 1? Pretty much everything other language that has such a mapping does false = 0, true != 0.
In one line, a vivid reminder of why I find perl so awful.
I can't wrap my mind around this complaint. "Why should you count on Perl treating booleans the way Perl treats booleans? Other languages don't treat booleans the way Perl treats booleans, so obviously you shouldn't rely on Perl treating booleans the way Perl treats booleans."
It's almost as if there were some democratic notion of boolean semantics where every language you know gets one vote.
It's a trick so it's easier to remember because while both sections look similar, the operators between them are actually doing different things.
i.e. => is a fatarrow (comma), while <= is less-than-or-equal. Replacing> with , results in
[ $x , $y ]->[ $x <= $y ];
Which is, arguably, less easy to remember.
Why does the array have to be explicitly dereferenced? Isn't it obvious from context?
Probably because the first set or brackets is an array reference creation and the second is an array reference subscript? There may be rules that need to be followed for the language to be parseable?
Why count on the mapping from boolean to int being false = 0, true = 1? Pretty much everything other language that has such a mapping does false = 0, true != 0.
Perl's comparison operators return numerical outputs for true/false, as that's how Perl handles true/false. What value would you expect for true, if there isn't a dedicated type?
In one line, a vivid reminder of why I find perl so awful
Eh, not my preferred syntax either. I do find that it's possible cool though.