Perl qq~~ and q~~ ability -> PHP?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
kitdekat
Forum Newbie
Posts: 1
Joined: Wed Apr 16, 2003 9:48 am

Perl qq~~ and q~~ ability -> PHP?

Post by kitdekat »

Perl has the ability to 'inline' HereDocs by using qq~~ (double quoting) and q~~ (single quoting) a portion of text exactly like a HereDoc does (parsing $vars while keeping nopn-escaped "s and 's as well) without taking up entire lines for start and end tags. Also the ~ symbol can be replaced by any character that you wont be using within the string, and if you do, can be escaped to still print it out. It also allows for multiple HereDoc conversions on a single line, examples as follows:

Code: Select all

echo <<< END_HERE1
remembers "quotes" and parses $vars
and 'remembers' new lines
END_HERE1;

echo join("\n", $array_list);

echo <<< END_HERE2
and continues.
END_HERE2;
can be done as follows:

Code: Select all

echo qq~... "quotes" and $vars\n~ . join("\n", $array_list) . qq~and ...\n~;
which allows more condensed code and, atleast i think, makes creating formatted HTML easier.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

But, why is this in "Suggestions"?
Image Image
Post Reply