Click to See Complete Forum and Search --> : perl stuff


Sweede
09-09-2001, 05:40 PM
PHP 4 supports the perl style <<< (heredoc) syntax.

i posted a message to a mailing list about using that instead of
echo "fads"
."<a href=\"".$var."\">fasd</a>";

and whatnot.

one guy said..

"I see no point in it. It imposes extra requirements, and offers no advantage."

Anyone can offer some `advice' for this guy to use heredoc instead of escaping everything with \ ?

The Kooman
09-10-2001, 12:11 PM
Originally posted by Sweede:
<STRONG>PHP 4 supports the perl style &lt;&lt;&lt; (heredoc) syntax.

i posted a message to a mailing list about using that instead of
echo "fads"
."&lt;a href=\"".$var."\"&gt;fasd&lt;/a&gt;";

and whatnot.

one guy said..

"I see no point in it. It imposes extra requirements, and offers no advantage."

Anyone can offer some `advice' for this guy to use heredoc instead of escaping everything with \ ?</STRONG>

I don't know how much of a help it is in PHP since its generating HTML code (and so all spaces are compressed into one) but being able to get rid of the "echo" clutter and the backslash clutter is a big bonus:

Just "shar" a small (text, for simplicity) file and try to see how you'd do it with just echoes and backslashes! Much simpler with a here-document, I'd say!

Just a matter of preference I guess ... but thats an off-the-hat statement!

[ 10 September 2001: Message edited by: The Kooman ]

Salmon
09-10-2001, 02:13 PM
It's a matter of style and preference.

Personally, I think they make the code look like total crap. And with PHP they can add extra confusion (large here docs might initially be mistaken for embedded HTML, etc).

However, there are plenty of folks who think they're great, and that's fine too.

TheLinuxDuck
09-20-2001, 03:44 PM
I tend to use escaped characters. I don't much fancy the here docs.. one main reason is line length.

Let's say I have two variables called $defaultWidth and $defaultHeight. Now, we want to push a table's beginning html code. With a standard escaped print, I can break the line down as:

print " &lt;table cellpadding=0 cellspacing=0 border=0 align=\"center\" ",
"width=$defaultWidth height=$defaultHeight&gt;\n";


This allows it to print out to look correct in the html document's source, and also leaves the line less than 80 chars, to fit in a terminal window/text window. Plus, it's easy to read and see what is going on.

But, a heredoc, if you want this line to look correct in an html document's source (i.e. be on one line), then you'll have to make the line extend 80 chars and IMHO, that is just plain ugly/wrong..

You could always break it down, so that it prints to two lines in the html source, but I don't like that. I want a line to be complete of itself in the html document.

Bear in mind this is my personal opinion... (^=

takshaka
09-21-2001, 06:48 PM
You know you can avoid escaping double-quotes by using the qq operator:


print qq~ &lt;table cellpadding=0 cellspacing=0 border=0 align="center" ~,
"width=$defaultWidth height=$defaultHeight&gt;\n";


Of course, that's a bad example since single quotes would've sufficed for the first line anyway :p

[ 21 September 2001: Message edited by: takshaka ]