Eric Johnson
Eric Johnson

Reputation: 17970

How do you comment a Perl regular expression?

How do you put comments inside a Perl regular expression?

Upvotes: 17

Views: 6226

Answers (2)

Eric Johnson
Eric Johnson

Reputation: 17970

Use the /x modifier:

my $foo = "zombies are the bombies";
if ($foo =~ /
             zombie  # sorry pirates
            /x ) {
    print "urg. brains.\n";
}

Also see the first question in perlfaq6.

Also it wouldn't hurt to read all of perlre while you're at it.

Upvotes: 24

ysth
ysth

Reputation: 98398

Even without the /x modifier, you can enclose comments in (?# ... ):

my $foo = "zombies are the bombies";
if ( $foo =~ /zombie(?# sorry pirates)/ ) {
    print "urg. brains.\n";
}

Upvotes: 18

Related Questions