tags:

views:

514

answers:

2

What does the colon mean in the following Perl program?

MAIN: {
    print "Hello\n";
}
+15  A: 

It separates a label (MAIN) from a block (the stuff between curly braces).

In Perl, a label is always suffixed with a colon, so you might argue the colon is part of the label.

JB
Thanks all upvoters: you've earned me the "Enlightened" badge! :-D
JB
"...you might argue the colon is part of the label," except that you don't use a colon when you refer to the label. For example, it's `redo MAIN;` not `redo MAIN:;`, so it's not a very good argument.
cjm
Ok, let's argue its part of the "labeling" then. FWIW, I personally don't think it's a great argument either, but the wording of the questions kind of begged for it.
JB
+10  A: 

The colon is a required separator of a label from the following block.

From perlsyn:

The LABEL is optional, and if present, consists of an identifier followed by a colon

DVK