in reply to Anonymity

Could you please provide some examples or descriptions of situations, where you fe(el||elt) like you said?
I mean, tell me why are they so cool and powerfull?
I also need to learn more about perl. Gimme a hint please :-)

Have a nice day
All decision is left to your taste

Replies are listed 'Best First'.
RE: RE: Anonymity
by snax (Hermit) on Nov 14, 2000 at 15:28 UTC
    Anonymity provides you with the ability to create very complex data structures. Say you're stuck with a flat ASCII file that really ought to be a database. You parse the lines, and create a named hash to represent your database. The values can now be array or hash references, so that the rest of the data in your record can be organized how you want it -- but how do you get as many arrays and hashes as you need, on the fly?

    Anonymous hashes and arrays, of course.

    Even better is a situation I just came across where I needed to build an array for each key, but I didn't know when I got to a key if I'd seen it before. So I just use

    # Rebuild the canonical list, but now we lose duplicates foreach my $name (keys %byname) { # First instance of the id number needs an array ref if (! $final{$byname{$name}}) { $final{$byname{$name}} = [ $name ]; } # Additional instances get pushed onto the existing # (anonymous) array else { push @{$final{$byname{$name}}}, $name; } }
    This is a cool example because the %byname hash was built from a hash that had array refs as values, and the arrays were filled with names, possibly duplicates. When I built the %byname hash, the duplicates get eaten up since they "point" to the same key, so that the %final hash looks a bit like the hash %byname was built from, but all the duplicate names are gone.

    I will be the first to admit that I need to master the

     -> 
    notation to make my code more readable and intuitive, though :)

      The problem with an anonymous hash structure is when it is used in a highly nested structure, I find it helps to produce state diagrams for each alternative of the structures implementation.

      If the structure is passed as parameter to another function, it is really useful to write a summary of the keys that the function requires to perform it's task.

      -- 
      
      Brother Frankus.