[comp.sources.d] Perl question: what do {{ and }} me

mcdaniel@uicsrd.csrd.uiuc.edu (07/01/88)

/* Written  4:22 pm  Jun 29, 1988 by bin@rhesus.primate.wisc.edu in
uicsrd.csrd.uiuc.edu:comp.sources.d */

> The perl 2.0 manual contains two examples that use {{ and }}
> instead of { and } to bracket subroutines.  One of them says
> to note the double curly brackets.  But what do they mean?
> The explanation is not in the manual, or at least I can't
> find it.

One example is at the end of ``Compound statements'', just before
``Simple statements'' (page 9 in my copy).  See the preceding text:

	The BLOCK by itself (labeled ot not) is equivalent to a loop
	that executes once.  Thus you can use any of the loop control
	statements in it to leave or restart the block. . . .  It's
	also nice for exiting subroutines early.  Note the double
	curly brackets: . . .

In ``Subroutines'' (page 28), it says that the syntax of ``sub'' is:
	sub NAME BLOCK

My interpretation is that a ``sub'' block isn't a ``proper'' block, in
that you can't do a ``last'' to break out of it.  You can, however,
break out of a normal block.  Thus, in ``{{ . . . }}'' in this
example, the outer braces are for ``sub'', and the inner braces are
so that the ``last'' works.  The other example, under the description
of ``open'' (page 20), also notes
		last;		# note block inside sub

> Yours,
> Paul DuBois
Best regards to Blanche, then.  :-)

-- 
Tim, the Bizarre and Oddly-Dressed Enchanter
Center for Supercomputing Research and Development
at the University of Illinois at Urbana-Champaign

Internet, BITNET:  mcdaniel@uicsrd.csrd.uiuc.edu
UUCP:    {ihnp4,uunet,convex}!uiucuxc!uicsrd!mcdaniel
ARPANET: mcdaniel%uicsrd@uxc.cso.uiuc.edu
CSNET:   mcdaniel%uicsrd@uiuc.csnet

lwall@devvax.JPL.NASA.GOV (Larry Wall) (07/09/88)

In article <42400007@uicsrd.csrd.uiuc.edu> mcdaniel@uicsrd.csrd.uiuc.edu writes:
: One example is at the end of ``Compound statements'', just before
: ``Simple statements'' (page 9 in my copy).  See the preceding text:
: 
: 	The BLOCK by itself (labeled ot not) is equivalent to a loop
: 	that executes once.  Thus you can use any of the loop control
: 	statements in it to leave or restart the block. . . .  It's
: 	also nice for exiting subroutines early.  Note the double
: 	curly brackets: . . .
: 
: In ``Subroutines'' (page 28), it says that the syntax of ``sub'' is:
: 	sub NAME BLOCK
: 
: My interpretation is that a ``sub'' block isn't a ``proper'' block, in
: that you can't do a ``last'' to break out of it.  You can, however,
: break out of a normal block.  Thus, in ``{{ . . . }}'' in this
: example, the outer braces are for ``sub'', and the inner braces are
: so that the ``last'' works.  The other example, under the description
: of ``open'' (page 20), also notes
: 		last;		# note block inside sub

Just to confuse things thoroughly, I've decided to add a return statement.
It'll show up in patch2.  Turned out to be fairly trivial to add, without
penalizing subroutines that don't use it.

Larry