Welcome to WebmasterWorld Guest from 54.234.244.30

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Multi line string assignment

Can strings span multiple lines?

     
8:41 pm on Feb 7, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4966
votes: 10


Can you do the following with Perl?

$myValue = "Blah blah blah
blah blah blah";

(notice the line break)

If not, will this work:

$myValue = qq|Blah blah blah
blah blah blah|;
9:05 pm on Feb 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 31, 2008
posts:661
votes: 0



Can you do the following with Perl?

$myValue = "Blah blah blah
blah blah blah";


yes.

If not, will this work:

$myValue = qq|Blah blah blah
blah blah blah|;


of course. there's more than one way to do it!
9:37 pm on Feb 7, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4966
votes: 10


Ok, I thought so, but was having a hard time finding a resource that said so explicitly. :) Thanks.
5:09 pm on Feb 8, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


qq is one of the cool things about Perl that you don't have, for whatever reason, in PHP. You can do

$var = qq|
This is $some_day and that
lands on a $weekdays{$some_day}.
|;

But in PHP, you have concatenate array variables, which makes it a little harder to debug and maintain.

$var = "
This is $some_day and that
lands on a " . $weekdays[$some_day] . "."
;

This is also why you see so many single quoted HTML attributes, which I abhor. I don't know why, they're perfectly valid. I just do. :-)

$var = "
here is the link
to <a href='$url'>your site."
;

Ahh. :-)

$var = "
here is the link
to <a href=\"$url\">your site."
;

It does have HEREDOCS, but it's a bit messy.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members