Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I escape '#' pound sign?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I escape '#' pound sign?
by ariels (Curate) on Feb 21, 2001 at 19:27 UTC
    Inside a regular expression (given the section we're in):
    $x = '# a comment'; print "$&\n" if $x =~ m/^\#.* # A comment! /x;
    (You have to backwhack the #, or m//x will consider it a comment.
Re: How do I escape '#' pound sign?
by ariels (Curate) on Feb 21, 2001 at 19:26 UTC
    Inside a regular expression (given the section we're in):
    $x = '# a comment'; print "$&\n" if $x =~ m/^\#.* # A comment! /x;
    (You have to backwhack the #, or m//x will consider it a comment.

    Originally posted as a Categorized Answer.

Re: How do I escape '#' pound sign?
by Anonymous Monk on Sep 08, 2000 at 13:01 UTC
    Simply by putting the pound inside quotes:
    $val = q(#); $val2= "#";
Re: How do I escape
by merlyn (Sage) on Sep 08, 2000 at 07:12 UTC
    Where would you need to escape it? {grin}

    Originally posted as a Categorized Answer.