[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My First Computer (was Computing Editorial)



In <lxy4a.263$A62.36863076@newssvr14.news.prodigy.com>, Kelly Hall wrote:

> "Dave Horsfall" <daveh@ci.com.au> wrote in message
> news:20030217095508.K68469@mippet.ci.com.au...
>> On Sat, 15 Feb 2003, Lee Hart wrote:
>>
>> > However, it is a *huge* language, with a philosophy of having lots of
>> > ways to do everything. That makes reading an existing Perl program
>> > quite a challenge. It also have some anti-intuitive aspects; print 1 +
>> > 2 + 3 is "7", but print (1 + 2) + 3 is "3".
>>
>> Which universe would this be?
> 
> I got the results the original poster described using both Perl 5.6.1 on
> WinXP and Perl 5.8.0 on RedHat 8.0.
> 
> I think it has to do with scalar and list contexts in Perl.

No, the problem is that Perl allows to call builtin functions with and
without parenthesis around the argument(s). In that case above it's
interpreted as '(print(1+2))+3' so it just prints the result of (1+2) and
the +3 is lost. It's easy to cure: 'print((1+3)+3)' and quite easy to
spot if you invoke perl with the parameter '-w'. Then the interpreter
gives a warning about the useless '+3'.

Ciao,
	Marc 'BlackJack' Rintsch