Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does colon mean in Perl?

Tags:

syntax

perl

What does the colon mean in the following Perl program?

MAIN: {
    print "Hello\n";
}
like image 621
hcs42 Avatar asked Sep 02 '09 12:09

hcs42


People also ask

What is double colon in Perl?

Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames - Use double colon (::) to separate package name components instead of single quotes (').

What does !~ Mean in Perl?

!~ is the negation of the binding operator =~ , like != is the negation of the operator == . The expression $foo !~ /bar/ is equivalent, but more concise, and sometimes more expressive, than the expression !($foo =~ /bar/)

What does <> do in Perl?

It's an operator. Specifically, the readline operator. There's a reference to it as the "angle operator" in perlvar, although there isn't actually any such operator.

What is $$ in Perl?

$$ The process number of the perl running this script. (Mnemonic: same as shells.) $? The status returned by the last pipe close, backtick (\`\`) command or system operator.


2 Answers

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.

like image 166
JB. Avatar answered Sep 20 '22 09:09

JB.


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

like image 28
DVK Avatar answered Sep 18 '22 09:09

DVK