[Tutor] Are you allowed to shoot camels? [kinda OT]

Nicholas.Montpetit at deluxe.com Nicholas.Montpetit at deluxe.com
Thu Feb 3 15:03:27 CET 2005


> (I am an ex-perler gone clean. Been straight for 5 years now with only 
> the occasional work forced binges.)
> 
> Perl was designed by a linguist. He wanted it to act like human language 

> -- which is not very consistent.

And from what I gather, quite effective.  :-)
 

> Personally, the thing that keeps me away from Perl is nested 
datastructures.
> 
> Python:
> 
> my_list = [....]
> a_dict = {.....}
> b_dict = {.....}
> my_list.append(a_dict)
> my_list.append(b_dict)
> 
> if my_list[0].has_key("foo"): print "Yes"
> 
> easy. Try that in Perl.

OK, sounds like fun:

my %a_dict = (...);
my %b_dict = (...);
my @my_list = (\%a_dict, \%b_dict);
if (exists $my_list->[0]{foo}) print "Yes\n";

And if you want to do it another way:

my @my_list = ( (...), (...) ); #define hashes in the (...)'s
print "Yes\n" if (exists $my_list->[0]{foo});


Btw, I'm skeptical that the code below does what you want it to do.  :-)
 
> my @my_list;         # remember those semicolons
> my %a_dict, %b_dict;
> push @my_list, %a_dict;
> push @my_list, %b_dict;
> if (exists $my_list->[0], "foo") print "Yes\n";
> # yes, references required, in Perl ick.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050203/a3f24801/attachment.html


More information about the Tutor mailing list