On Fri, Apr 12, 2002 at 02:14:36PM -0700, Erik Steven Harrison wrote: > > -- > > On Fri, 12 Apr 2002 18:27:11 > abigail wrote: > >On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: > >> [EMAIL PROTECTED] writes: > >> > > >> > Why isn't > >> > > >> > if %foo {"key"} {print "Hello 1"} > >> > > >> > equivalent with the perl5 syntax: > >> > > >> > if (%foo) {"key"} {print "Hello 1"} > >> > > >> > Which keyword is it expecting? > >> > >> Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased > >> on my part. The closing brace of {"key"} only ends the statement if it > > > As i understand it (Tell me if I'm wrong) This > > %hash {key}; > > will not work, because space between the hashname and the brace was no longer >allowed. This allows for
"Will not work" is not correct. "%hash {key}" is parsed as an expression followed by a block. Whether that will work depends on the context. 'if' for instance is followed by an expression and a block..., so if %hash {key} *will* work, except it does something totally different than one might expect. > > if %hash{key} { ... } > > and also > > if $scalar { ... }. > > The only other white space rule is that white space after the closing brace of a >closure, when that closure is the last argument of a user defined sub get's treated >as a semicolon if there is nothing else on that line. This allows custom iterators to >parse (or appear to parse) like builtins. > > myforeach @arry, %hash, $scalar { > ... > } > #No semicolon required! > > What problems does this seem to cause - I don't see anything wrong. I don't see how >(except in the case of closure as last argument) how it matters one way or another >what kind white space appears between tokens. > > What am I missing? What you are missing is the new white space rule: \s+{ } shall be always be a block. Hence the difference between "%hash {foo}" and "%hash{foo}". Abigail