Main Content

-> , >= and => in Perl

Archive - Originally posted on "The Horse's Mouth" - 2006-11-18 10:44:05 - Graham Ellis

Yes, Perl is eclectic - lots of things it can do, taken from lots of places and so, yes, it does have all three of those operators!

-> Run the method named to the right on the object named on the left

>= Return 1 (a true value) if the expression to the left is numerically greater than the expression to the right

=> Normally used to indicate a key, value pair for entry into a hash. In fact, the => operator is the equivalent of a , (a comma) which can be used instead - the=> is just provided to make the your code easier to read, and (in some circumstances) saves you the need to quote keys.

Examples:
$kgs = $current->getweight();
# Get the weight of the $current object

print "heavy\n" if ($kgs >= 100);
# Print out if $kgs is numerically 100 or greater

%info = (weight => 120, height => 1850);
# Set a hash with 2 key, value pairs