in reply to Trying to understand aliasing (*var)

Typeglobs, ie *foo are mostly an artifact of Perl 4, which didn't have references; they will be removed completely in Perl6

A typeglob can be though of as a wildcard: *foo represents all of $foo, @foo, %foo etc. When you assign a reference to a typeglob, it replaces the slot in the typeglob corresponding to the the type of the reference, with that value; so

*foo = [ 1,2,3 ]
acts like
@foo = (1,2,3)
except that you are actually replacing @foo with with a new array rather than just replacing its contents.

To get your code to compile, add an  our $z at the top.

Dave.

Replies are listed 'Best First'.
Re^2: Trying to understand aliasing (*var)
by BrowserUk (Patriarch) on Feb 11, 2005 at 14:18 UTC
    they will be removed completely in Perl6". So that might be a reason to avoid this particular type of magic,...

    By that token, you should also avoid $array[ 1 ] = 2;, because that won't work in p6 either.

    Nor will $hash{fred}=27;.

    Nor will do { n++; } while $n < 10;.

    Nor will print ( 'Hello, world!" );.

    Nor will while( <DATA> ) { my @array = split'\t'' };.

    Nor will keys %hash = 1000;.

    Nor will for( my i=0; $i < @array; i++ ) {...};

    Nor will $#array = 1_000_000;.

    Read more... (357kB)

    Nor will open FILE, '<', 'myfile' or die $!;.

    But then again, local *array = \$arrayRef; won't be needed, because the syntax for

    my @array; push @array, $somevalue;

    And

    my $array = []; push @array, $someValue;

    Will be the same...or so it was at some point in time.

    So, whilst P5 doesn't provide an alternative to the simplicity of

    local *array = $aRef; push @array, $someValue;

    it is a very useful construct to know.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.