Kevin Pfeiffer wrote: > Hi Paul, > > sub get_class_types > > { > > my $self = shift; > > > > my $roots = []; > > my $unresolved = []; > > > > while (my ($class, $props) = each %{$self->{classes}}) > > { > > push @{$props->{parent} ? $unresolved : $roots}, $class; > > } > > > > ($roots, $unresolved) > > } > > > > Why "my $roots = [];" and not "my $roots = '';" (for example)? Is it just > style or is there is some devious/useful intent here?
Not just style at all. This is very important to get clear. These are very different declarations. The string ';' is a scalar. The brackets represent a reference to an anonymous array, which is here initialized as empty. The array so referenced will persist as long as any reference points to it. Perl offers an under-the-hood service called reference counting that keeps track of the number of in-scope identifiers that refer to any allocated structure. When the last reference goes out of scope or is otherwise redfined the memory is freed for re-allocation. This offers a very tidy way to have an array or hash for just as long as you need it. In my case, $root_classes and $unresolved_classes will disappear when the direct caller of this function finishes. The function exists to generate these two references and deliver them to the caller.. Get to know your references. They are the key to power programming. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]