in reply to Re^2: a reference by any other name...
in thread a reference by any other name...

If there isn't an appropriate, simple way to do this I'm going to be very surprised.

You can do it pretty easily with package variables:

@array1 = 0..9; *array2 = *array1; pop @array1; print "@array2\n"; pop @array2; print "@array1\n"

But I think the flaming death risk is pretty high here, too, though for different reasons.

Update: you can also use a similar technique to alias to a reference, though again the alias is a package variable, and as such carries all the associated caveats. Example:

sub foo { my ($ref) = @_; local *nonref = $ref; pop @nonref; print "@$ref\n"; pop @$ref; print "@nonref\n"; } foo([ 0 .. 9 ]);

Replies are listed 'Best First'.
Re^4: a reference by any other name...
by Aristotle (Chancellor) on Feb 20, 2006 at 03:08 UTC
    @array1 = 0..9; *array2 = *array1;

    That nukes the entire *array2 glob. I think you want

    @array1 = 0..9; *array2 = \@array1;

    Makeshifts last the longest.

Re^4: a reference by any other name...
by blogical (Pilgrim) on Feb 20, 2006 at 03:33 UTC
    That looks like the sort of laziness I'm looking for- although likely a bit of overkill... aha, pg 79 of the camel 3rd ed.:
    *foo = \$bar;
    But I see that it creates a global, whereas I really only want a lexical....
    local *foo = \$bar;
    would seem to come close though. Although, if I can't use a lexical, perhaps I should just declare our %bar before the function call, and just call it what it is without bothering to pass a reference... that seems like a bad solution though.

    Thanks! I learned something. Of course, I'm always up for learning more, if any other smartymonks care to divulge their secrets.