[sf-perl] passing array and hash references

Quinn Weaver qw at sf.pm.org
Fri Sep 29 00:50:50 PDT 2006


On Fri, Sep 29, 2006 at 12:34:22AM -0700, Quinn Weaver wrote:

> [about Data::Alias]

> I just read about it
> in _Perl Best Practices_, and your post jogged my memory.

The use Damian suggests for it, BTW, is for modifying elements in loops:

# Damian's code, not mine
for my $agent_num (0..$#operatives) {
    alias my $agent = $operatives[$agent_num];

    if ($on_disavowed_list{$agent}) {
        $agent = "[DISAVOWED]"; # Changes the copy in @operatives --QDW
    }
}

The larger point he's making is that you should "extract" $agent into an
alias rather than doing something like this:

for my $agent_num (0..$#operatives) {
    if ($on_disavowed_list{$operatives[$agent_num]}) {
        $operatives[$agent_num] = "[DISAVOWED]"; # Too much array subscripting!
    }                                            # Hard to read. --QDW
}

--
qw (Quinn Weaver); #President, San Francisco Perl Mongers
=for information, visit http://sf.pm.org/weblog =cut


More information about the SanFrancisco-pm mailing list