Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Indented HEREDOC?

by Ovid (Cardinal)
on May 26, 2006 at 07:46 UTC ( #551787=note: print w/replies, xml ) Need Help??


in reply to Indented HEREDOC?

I posted a snippet which will handle this at Unindent HERE docs. Also, if you want to indent the closing token, put the leading token in quotes.

print <<' END'; This is text. END

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^2: Indented HEREDOC?
by reasonablekeith (Deacon) on May 26, 2006 at 08:41 UTC
    sorry for the nit-pick, but given the OP's example showed a variable, the example really should have been.
    if ($foo) { print <<" STRING"; foo is $foo. STRING }
    With the difference being that I've used double quotes and not single quotes. I mention it becuase I missed this the first time I saw heredocs, and didn't realise it caused the entire contents of the heredoc to be either interpolated or not, dependant on whether you used double or single quotes, respectively.

    The output of the above would obviously be

    foo is whatever_is_in_foo

    as opposed to single quotes, which would give

    foo is $foo
    ---
    my name's not Keith, and I'm not reasonable.

      No need to apologize for the nitpick. It's a point well-taken.

      Cheers,
      Ovid

      New address of my CGI Course.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://551787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2019-09-17 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (218 votes). Check out past polls.

    Notices?