[comp.lang.perl] do BLOCK bug?

vsh@etnibsd.UUCP (Steve Harris) (08/02/90)

I'm running perl 3.0, patchlevel 15.  Apologies if this issue has
already been addressed in this newsgroup and/or if it is fixed in a
more recent patch.

If I run the following code, which is taken directly from the manual
(the section describing the lack of a switch statement):

	foo: {
		/^abc/ && do { $abc = 1; last foo; }
		/^def/ && do { $def = 1; last foo; }
		/^xyz/ && do { $xyz = 1; last foo; }
		$nothing = 1;
	}

I get the following errors:

	syntax error in file t.pl at line 3, next token "/^def/"
	syntax error in file t.pl at line 5, next token "$nothing"
	Execution aborted due to compilation errors.

The errors go away if I place a semicolon after each do BLOCK
(presumably the do BLOCK is expecting an optional modifier, e.g.:)

	do BLOCK if EXPR;

This looks like a bug, in the documentation if nowhere else.
-- 
Steve Harris - Eaton Corp. - Beverly, MA - uunet!etnibsd!vsh

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/KT) (08/05/90)

As quoted from <1137@etnibsd.UUCP> by vsh@etnibsd.UUCP (Steve Harris):
+---------------
| 	foo: {
| 		/^abc/ && do { $abc = 1; last foo; }
| 		/^def/ && do { $def = 1; last foo; }
| 		/^xyz/ && do { $xyz = 1; last foo; }
| 		$nothing = 1;
| 	}
| 
| 	syntax error in file t.pl at line 3, next token "/^def/"
| 	syntax error in file t.pl at line 5, next token "$nothing"
| 	Execution aborted due to compilation errors.
| 
| The errors go away if I place a semicolon after each do BLOCK
| (presumably the do BLOCK is expecting an optional modifier, e.g.:)
+---------------

More precisely, you are using "do BLOCK" as an expression, and the complete
expression needs a semicolon.  (That is, the statement you are ending with a
semicolon has as its "primary" operator not "do", but "&&".)

Given that "do" can be used in this way, there's no way to get around the
semicolon without uglifying the syntax description considerably.

++Brandon
-- 
Me: Brandon S. Allbery			    VHF: KB8JRR/KT on 220 (soon others)
Internet: allbery@NCoast.ORG		    Delphi: ALLBERY
uunet!usenet.ins.cwru.edu!ncoast!allbery    America OnLine: KB8JRR