in reply to Re^3: Short form (ternary) if else
in thread Short form (ternary) if else
Note: while naming variables the same as Perl key words is allowed (e.g. $cmp, (cmp is a key word), I personally try to avoid this).#!/usr/bin/perl -w use strict; my $x = 2; my $y = 3; my $cmp_result = $x <=> $y; print $cmp_result # -1
for comparison in a string context, use cmp:
Update: As to the history, I have no idea why <=> is called the "spaceship" operator, but that is the common usage.my $cmp_result = $stringX cmp $stringY;
|
|---|