From: Dr.Ruud on
A. Sinan Unur schreef:

> if( exists $hash{$key} ) {
> print "$hash{$key}\n";
> }


Hunting for alternatives:

$ echo 'if( exists $hash{$key} ) { print "$hash($key)\n"; }' \
| perl -MO=Deparse,-x7

exists $hash{$key} and do {
print "$hash($key)\n"
};

I don't know why the do-block is needed.


$ echo 'print "$hash{$key}\n" if exists $hash{$key};' \
| perl -MO=Deparse,-x7

exists $hash{$key} and print "$hash{$key}\n";

--
Affijn, Ruud

"Gewoon is een tijger."
From: A. Sinan Unur on
"Dr.Ruud" <rvtol+news(a)isolution.nl> wrote in news:dro98o.vk.1
@news.isolution.nl:

> A. Sinan Unur schreef:
>
>> if( exists $hash{$key} ) {
>> print "$hash{$key}\n";
>> }
>
>
> Hunting for alternatives:
>
> $ echo 'if( exists $hash{$key} ) { print "$hash($key)\n"; }' \

Check out the missing curlies in the second hash access. Not that it
changes anything.

Sinan
--
A. Sinan Unur <1usa(a)llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

From: rhorizon74 on
Just wanted to check if i was missing anything, Didnt think anybody
woud get offended if i questioned a programming language, didnt realize
that the perl way was set in stone.

Thanks for your help anyways

From: A. Sinan Unur on
[ Please quote some context when you reply. ]

"rhorizon74" <rhorizon74(a)yahoo.com> wrote in news:1138729475.641979.180700
@z14g2000cwz.googlegroups.com:

> Just wanted to check if i was missing anything, Didnt think anybody
> woud get offended if i questioned a programming language, didnt realize
> that the perl way was set in stone.

You did not offend anyone, at least not me.

It was obvious that you had not read either the link I posted, or the
documentation, and yet you were still opining about what should and should
not be. With that attitude, I rather not read your posts.

Sinan

--
A. Sinan Unur <1usa(a)llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

From: Ala Qumsieh on
rhorizon74 wrote:
> Thanks for the help.
>
> That explains what is happening (i had used the exists approach to work
> around).
> But it does seem bogus that for a simple print statement i need to
> check each and every level. I havent seen too many languages do
> something like this (i may be wrong).
> But a print statement shouldnt really be creating any data.

It is not the print(), it is the fact that you are trying to access the
value of the ABC key. If hashes didn't autovivify, then you won't be
able to do this:

$hash{key1}{key2}{key3} = 'value';

before you actually create all the keys explicitly:

$hash{key1} = {};
$hash{key1}{key2} = {};
$hash{key1}{key2}{key3} = 'value';

Autovivification is a Good Thing (tm).

--Ala