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



Hi,

The code i posted is just a sample, i was trying to understand exactly
what was happening.

The are a bunch of scenarios where a different module is supposed to
build a hash, and my module needs to print the values. In which case
for each level of nesting of a hash i will be forced to check if the
node exists (starting with the outer hash and going onto the inner
hash). With my limited exposure to perl i guess it seemed a bit
diffcult to grasp.

I do understand the efficiency it provides while creating a structure.

I did check with a lot of colleagues some who were not exactly novices
like me with way much more experience in perl and they too had come
across this scenario (they grappled with this by adding checks for each
level before printing the values) , but to be honest none with any
exact knowlege of vivication. So it did seem like this problem was
commonly faced by a lot of programmers.


Thanks for the reply




Uri Guttman wrote:
> >>>>> "r" == rhorizon74 <rhorizon74@xxxxxxxxx> writes:
>
> r> Thanks for the help.
> r> That explains what is happening (i had used the exists approach to work
> r> around).
> r> But it does seem bogus that for a simple print statement i need to
> r> check each and every level. I havent seen too many languages do
> r> something like this (i may be wrong).
> r> But a print statement shouldnt really be creating any data.
>
> if you read my article (which sinan posted the url for) then you will
> learn more about autoviv and why it is like it is. and even calling
> exists will do the same thing (but that is being fixed in perl6). the
> win of autovivication is much greater then the loss of rare code like
> yours. if you didn't have it you would need to check each time you used a
> reference in structure and either assign a new one or use the existing
> one. that is massively ugly and clumsy (and i have seen newbies coding
> like that all the time).
>
> uri
>
> --
> Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

.



Relevant Pages

  • RE: Simplest hash initialization with no value
    ... in a print statement which is something like this: ... You can't "declare" a hash slice. ... Your original question was "how to initialize a hash". ...
    (perl.beginners)
  • Re: print statement creates key in hash with reference to empty array??
    ... r> The are a bunch of scenarios where a different module is supposed to ... r> build a hash, and my module needs to print the values. ... <snip of my entire quoted post> ...
    (comp.lang.perl.misc)
  • Re: Composite Keys with pairs generic collections
    ... Conversely, if the hash functions of the individual members *don't* produce nicely distributed hash codes, what sort of algorithm would minimize the damage for the composite hash code? ... Values don't tend to be uniformly distributed - values and are likely to come up in the same map in various scenarios, as are various values. ...
    (microsoft.public.dotnet.languages.csharp)
  • HoA problem
    ... I lose the hash value in the second last print statement. ... Any clues would be appreciated ... use strict; ...
    (perl.beginners)