here document

Linux shell script heredoc example

I was just working on my Linux Teleport command (Linux cd command with a history), and ran across the code below, which essentially shows how to use a form of "heredoc" syntax in a Bash shell script. This approach uses the Linux cat command, but functions just like the heredoc syntax in languages like Perl.

Here's the source code I just came across:

How to use a here document in PHP

PHP here document FAQ: How do I create a here document in PHP?

If you ever need to use a "here document" in PHP, here's a short example of the PHP here document syntax:

<?php

print <<< END
Four score and seven years ago
our fathers set onto this continent
(and so on ...)
END;

?>

I believe the closing tag you use ("END" in my case) must begin in the first column. This is typical with here document syntax, but I haven't tested it in PHP.

Recent Perl tutorials (Tue, Aug 5, 2003)

Cool, I've been back to Perl for a few days. I'd forgotten what a cool language it is. Here are two brief Perl tips related to my recent work:

Use Perl here documents to print multiple lines of output

Summary: How to use Perl here documents, i.e., the Perl heredoc syntax.

Perl offers a convenient way of printing multiple lines of output through an interesting feature known as a "Perl here document". A here document, or heredoc, lets you easily store multiple lines of text in a Perl variable.

A multiline Perl here document works like this:

Syndicate content