Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Hash values and constants

by ihb (Deacon)
on Jan 12, 2003 at 15:28 UTC ( #226275=note: print w/replies, xml ) Need Help??

in reply to Hash values and constants

Good question.

First a quick note: Although %hash->{key} works you shouldn't do that. $hash{key} is the right way to use a hash. This is a known bug.

Anyhow, the problem boils down to that   $hash{KEY}
is interpreted as   $hash{'KEY'}
and that a bareword to the left of => also is interpreted as a string. So what you have is:
my %hash1 = ('TESTVALUE', 'OK'); my %hash2 = (123, , 1);
What you want to have is   my %hash1 = (TESTVALUE() => 'OK');
or   my %hash1 = (TESTVALUE, 'OK');
When getting the value with the constant you need to make it a non-bareword:   $hash1{+TESTVALUE}
or   $hash1{TESTVALUE()}
I intentionally avoided mentioning & as a way of disambiguate the constant. This is because it will confuse and mislead people to think that you can do &foo; instead of foo(), which isn't the case. See perlfaq7.

Hope I've helped,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://226275]
[davido]: yeah, umount -f isn't powerful enough.
[tye]: probably something in the init subsystem that does the mounting that you could disable and reboot.
davido needs to close laptop to board flight home from yapc.
[davido]: I'll look into it in a few hours probably.
[davido]: when i do get to that point I think I'll do it in a vm snapshot just in case. :)
[oiskuu]: tye, you were right: loginuid/sessionid are part of task struct if compiled with AUDITSYSCALL. I have some doubts if you should actually depend on that feature.
[Corion]: oiskuu: Depends on what you want to do with that information
[tye]: I'm not depending on that feature. But I could in this environment. I'm using getlogin(). shrug
[Corion]: For benign logging (which user started this DB instance), it's OK

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-06-23 20:09 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (555 votes). Check out past polls.