On Tue, 1 May 2001, Jonathan Peterson wrote:
> I'm sure there's a good reason for it, but the code below gives a syntax
> error. I think it ought to do what it looks like it ought to do. What's
> the reason?
>
> $foo = 'bar';
> $foo =~ /bar/ and {print "yes"; print "yes again";}
>
... and do { print ... };
> gives: syntax error at test line 2, near "; print"
>
> $foo = 'bar';
> $foo =~ /bar/ and {print "yes";}
>
> gives: syntax error at test line 2, near ";}"
>
.. and do { print .. };
It is the semicolon that fucks this one.
> $foo = 'bar';
> $foo =~ /bar/ and {print "yes"}
>
> prints "yes" as expected.
>
> What's going on, eh?
>
You missed the :
Useless use of scalar ref constructor in void context at foo.pl line 2.
Odd number of elements in hash assignment at foo.pl line 2.
printing "yes" is a side affect :)
It thinks that it is a hash ref in a void where the first and only element
is the result of 'print "yes"' er 1 I think :)
/J\