Welcome to WebmasterWorld Guest from 54.167.82.170

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Multi line string assignment

Can strings span multiple lines?

     

Fotiman

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

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



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|;

janharders

9:05 pm on Feb 7, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member




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!

Fotiman

9:37 pm on Feb 7, 2011 (gmt 0)

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



Ok, I thought so, but was having a hard time finding a resource that said so explicitly. :) Thanks.

rocknbil

5:09 pm on Feb 8, 2011 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month