Python vs. Perl

Tim Hammerquist tim at vegeta.ath.cx
Wed May 30 07:55:28 CEST 2001


Jonathan Gardner <gardner at cardomain.com> wrote:
> On Saturday 26 May 2001 02:17 am, Thomas Wouters wrote:
> >
> > The => token simply quotes the preceding token, and then translates
> > itself into a comma. So
> >
> >  {key1 => 'value1', key2 => 'value2'};
> >
> > is the same as the second example above.
> 
> Which stinks, because you have to make sure that 'key1' is a token. For 
> instance, you can't do this:
> 
> (1=>'one', the second one=>'two')
> 
> because '1' won't be quoted, and 'the second one' has spaces. So it's a 
> Neat Trick (TM) that you can only use once in a while.

Precisely what do you mean by "'1' won't be quoted"?
Whether defined ( 1 => 'one' )  or  ( '1' => 'one' )
they are still accessible via $hash{1} or $hash{'1'}

As for { the second one => 'two' }, I would do my best to find a better
hash key.  If I couldn't avoid this as a key, it's not that hard to
surround it with quotes, which Python users do anyway.  There's nothing
in Perl that says you _must_ use barewords for hash keys.  And using =>
as a synonym for a comma allows:

: %hash1 = ( '1' => 'one', '2' => 'two', '3' => 'three' );
: @array = %hash1;
: print join(',', at array), "\n";
: %hash2 = @array;
: print "$_ = $hash2{$_}\n" for keys %hash2;

1,one,2,two,3,three
1 = one
2 = two
3 = three

> Which kind of makes it confusing for everyone involved. Why even have that 
> behavior if it works only in certain instances?

It places the ultimate decision in the coder's hands.

> As a sidenote, I was reading that if you have a barewored (which 'the', 
> 'second', 'one' all are) they are considered to be quoted in earlier 
> versions of perl.

Did this version of Perl also require all sub calls to be preceded by a
& thus:
    &foo;

> Which is further proof that perl is a very confusing language.

Then stick with Python.  Confusing is one thing Python is rarely accused
of.

-- 
-Tim Hammerquist <timmy at cpan.org>
Your question doesn't make any sense. You might as well ask whether
it is possible to grow vegetables from a painting, without becoming
Wednesday first.
	-- Abigail, c.l.p.misc



More information about the Python-list mailing list