> (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@python.org
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor