assigning values in python and perl

J. Peng peng.kyo at gmail.com
Thu Jan 17 08:20:36 CET 2008


On Jan 17, 2008 2:55 PM, Hrvoje Niksic <hniksic at xemacs.org> wrote:
>
> @$ref = (4, 5, 6) intentionally assigns to the same list pointed to by
> the reference.  That would be spelled as x[:] = [4, 5, 6] in Python.
> What Python does in your example is assign the same as Perl's $ref =
> [4, 5, 6].  So they're not so different after all.
>

Yup,you're so right.This test below in perl is the same as in python.
So at before I may got mistaken by myself.Thanks all.

$ cat t1.pl
sub test {
    my $ref = shift;
    $ref = [4,5,6];
}

my @a = (1,2,3);
test(\@a);

print "@a";

$ perl t1.pl
1 2 3



More information about the Python-list mailing list