On Tue, Aug 07, 2001 at 11:49:12AM -0500, Jay Strauss wrote:
> What I really want to do, is perform some housekeeping and variable
> initialization within a subroutine (so that I can stick it at the bottom of
> the source and not look at it all the time).  So I've been monkeying with:
> 
> use strict;
> 
> my %arg = (quiet=>"yep");
> housekeeping(\%arg);
> 
> sub housekeeping
> {
>    print keys %{$_[0]}, "\n";
>    my %arg;
>    *arg = \%{$_[0]};
>     print keys %arg, "\n";
> }

You would need local *arg, not my %arg - but don't do it.

local *arg declares *arg in the global namespace, and makes a local
version of it (somewhat counterintuitive).  I've messed around with
this a lot.  So this means that there'll be a global mapping
$arg, %arg, @arg and &arg, just to accomplish aliasing.  This is,
needless to say, very kludgeful unless you're only dealing with
globals anyway (which, in itself, is pretty kludgeful).

Perl 6 will apparently have an ability to alias locals as well, but in
the meantime, I suggest sticking with references.  FWIW, though, the
above is fairly hard to read - I'd prefer '$args = shift;' at the top
of the subroutine, and then use %{$args} or $args->{...} to use the
reference.

Micah


Reply via email to