How to best explain a "subtle" difference between Python and Perl ?

Palindrom demarcheb at gmail.com
Tue Aug 12 18:17:33 CEST 2008


Hi everyone !

I'd like to apologize in advance for my bad english, it's not my
mother tongue...

My girlfriend (who is a newbie in Python, but knows Perl quite well)
asked me this morning why the following code snippets didn't give the
same result :

### Python ###

liste = [1,2,3]

def foo( my_list ):
    my_list = []

foo(liste)

print liste# she expected liste to be an empty list

### Perl ###

@lst =(1,2,3);
$liste =\@lst;
foo($liste);
print "@lst\n";

sub foo {
 my($my_list)=@_;
 @{$my_list}=()
}

I have to admit that I don't know how to clearly explain to her the
differences between these results.
Could someone please help us understand these difference between
Python and Perl ?

Thanks in advance,
P4|1ndr0m



More information about the Python-list mailing list