Re: print statement creates key in hash with reference to empty array??




rhorizon74 wrote:
> In the code below the print val statement actually creates an key 'ABC'
> in the hash if it does not exist ( i wanted to print the value of the
> 0th element in an array , the reference to which is stored in a hash
> with key 'ABC').
>
> Why should a print create a new key, shouldnt it just print undefined,
> and not create any new key.
>
> Thank you
> Code:
>
> use strict;
> use Data::Dumper;
> &main();
>
> sub main
> {
> my %a;
> my $aref = \%a;
>
> print "val: @{$aref->{ABC}}[0]\n";
> print Dumper($aref)."\n";
> }
>
>
> Output:
> val:
> $VAR1 = {
> 'ABC' => []
> };

lookup autovivification.

.



Relevant Pages

  • print statement creates key in hash with reference to empty array??
    ... In the code below the print val statement actually creates an key 'ABC' ... in the hash if it does not exist (i wanted to print the value of the ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: print statement creates key in hash with reference to empty array??
    ... > In the code below the print val statement actually creates an key ... > 'ABC' in the hash if it does not exist (i wanted to print the value ... > hash with key 'ABC'). ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: Konstante als Referenz auf anonymen Hash
    ... Hash darstellt. ... Über 'print ABC->' kann ich nun auf die einzelnen Elemente zugreifen. ... Wie kann ich aber z.B. mit einer foreach Schleife über alle im Hash vorhandene Elemente iterieren, wenn die Referenz über eine Konstante gespeichert ist? ... foreach my $keys (keys ABC) { ...
    (de.comp.lang.perl.misc)
  • Konstante als Referenz auf anonymen Hash
    ... die eine Referenz auf einen anonymen ... Hash darstellt. ... Über 'print ABC->' kann ich nun auf die einzelnen Elemente ... foreach my $keys (keys ABC) { ...
    (de.comp.lang.perl.misc)
  • Re: How to find a word in wordlist
    ... > I have wordlist file having format: ... > # check.pl abc ... you could read the entire file into a hash. ... of memory, but thereafter, lookups are very fast. ...
    (comp.lang.perl.misc)