Why use Perl when we've got Python?!
John W. Stevens
jstevens at basho.fc.hp.com
Fri Aug 13 23:05:12 EDT 1999
>
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc,
> "John W. Stevens" <jstevens at basho.fc.hp.com> writes:
> :Compare, also:
> :
> :list = ( "One", 1, 1.0 )
> :dict = { "Test" : list }
> :
> :t = list.append( dict )
>
> That's illegal. You've used a list operation
> on a tuple.
Yes, it is. I should have used a list, and I should have tested the
code, first.
>
> :print t[1]["test"]
> :print t
>
> Now I'm confused. The return from value from a list append
> operation is None. Are you sure you mean that? Furthermore,
> you have to "test" element, just a "Test" one.
>
> I think I'm going to assume you meant this:
>
> list = [ "One", 1, 1.0 ]
> dict = { "Test" : list }
> list.append(dict);
>
> or maybe that was
>
> t = [ list, dict ]
>
> :to the equivalent Perl code:
> :
> :Uh. . .
> :
> :Uh. . .
> :
> :Darn, I can't get my example to work (my Perl book
> :has been borrowed, while the Python example was done
> :from memory. . . I know this requires references, but
> :for the life of me, cannot remember exactly how to
> :state this)! Anybody who wants to, please show an
> :equivalent example.
> :
> :Anybody? Here's your chance to show what a Perl-DWIM-wit
> :I am. . . :-)
>
> $list = [ "One", 1, 1.0 ];
> $dict = { "Test" => $list };
>
> And then either
>
> push @$list, $dict;
>
> or else
>
> $t = [ $list, $dict ];
Thanks for the two missing magic characters (@$, and =>). I always
have to look them up.
The fact that you have a $dict that has $, instead of a %, is
very confusing.
> The bottom line is that that is hardly any different from what
> you had.
I beg to differ. The operations are the same as some other equivalent
operations, but require different syntax. . . something that you
already railed against in Python.
John S.
More information about the Python-list
mailing list