in reply to Hash values and constants
As you see, you do not have to use the comma instead of the double arrow - as long as Perl knows you mean the left side to be an expression, not a string. The same is true for hash lookup curlies. Note that prepending a plus sign won't work for the fat comma, though appending parens will work for the hash lookup. It's a bit confusing at first to remember which rules apply where, but you'll get used to them quick. In practice I find the specific rules and exceptions chosen to be the most convenient ones.#!/usr/local/bin/perl -wl use strict; use constant TESTVALUE => 1; my %hash1 = (TESTVALUE() => "OK"); my %hash2 = (123 => TESTVALUE); my $hashValue; print $hash1{1}; print $hash1{+TESTVALUE}; print $hash1{$hash2{123}};
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash values and constants
by ihb (Deacon) on Jan 12, 2003 at 16:39 UTC |