|
|
|
|
|
by arc_of_descent
4567 days ago
|
|
It prints the greater variable between $x and $y. [$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.