develooper Front page | perl.perl5.porters | Postings from October 2009

Re: "If" your subscript goes bump in the night

Thread Previous | Thread Next
From:
Abigail
Date:
October 31, 2009 12:39
Subject:
Re: "If" your subscript goes bump in the night
Message ID:
20091031193909.GA24264@almanda
On Fri, Oct 30, 2009 at 06:59:23PM -0400, George Greer wrote:
>> On Fri, Oct 30, 2009 at 8:33 AM, John Peacock
>> <john.peacock@havurah-software.org> wrote:
>>       On 10/28/2009 12:14 AM, George Greer wrote:
>>             $ ./perl -e 'if 0 { print "hi!\n"; }'
>>             $ ./perl -e 'if 1 { print "hi!\n"; }'
>>             hi!
>>             $ ./perl -e '$a{test} = 1; if $a{test} { print
>>             "hi!\n"; }'
>>             syntax error at -e line 1, near "; }"
>>
>>
>> A) You didn't tell us what version of Perl you are testing with...
>> B) You are not testing what you think you are testing
>>
>> Try this instead:
>> ./perl -e '$a{test} = 1; if ($a{test}) { print "hi!\n"; }'
>> hi!
>>
>> Those parentheses are not optional.  In fact, I can't execute your
>> first two examples without getting a syntax error as well:
>>
>>
> On Fri, 30 Oct 2009, Eric Brine wrote:
>> His post wasn't clear, but given the result from the first two tests, it
>> looks like he's working on making them optional.
>
> Yes, exactly.  The arrow-less subscripting shortcut is biting me though  
> because you can legally write:
>
> 	$hash {one} {two} {three} = 1;
>
> which makes the grammar/tokenizer have a hard time deciding where to 
> start a block versus a hash in the ()-less 'if'.  The existing logic to 
> decide what's a block and what's a hash (S_intuit_more) isn't exactly  
> straightforward but it works for the existing cases.


The most important reason I've no interest in Perl6, up to the point I'm
more likely to become a Java programmer than to ever write a Perl6 program
is that Larry forbid the usage of white space between '$hash' (or should I
say '%hash'?) and its subscript. A curly brace preceeded by whitespace is
always a block in Perl6.

He did this to be able to leave the parens of an if.



Abigail



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About