in reply to Concatnate long statement

Perl is a free-form language when comes to syntax layout. You don't need special operator to break your statement into as many lines as you like, or as your eyes can handle. But I'm not going to write a subroutine with that many arguments. I either use hash (for using named parameters instead of positional parameters), or break up the subroutine.

The same applies with string. Just type in the long string, and break it at your will.

my $str = "This string is not that long but I break it anyway becauase Perl allows me to do so and I just want to do it this way. But remember, there will be newlines inserted between lines";
Or, if you like, use the concatenation operator:
my $str = "This string is not that long" . " but I break it anyway becauase" . " Perl allows me to do so and I just want to" . " do it this way. But remember, there will not" . " be newlines inserted between lines" . " unless I say it explicitly," . " like\n" . " this";
Many Perl programmers, however, prefer to use here-doc syntax:
my $str = <<EOF; This string is not that long but I break it anyway becauase Perl allows me to do so and I just want to do it this way. But remember, there will be newlines inserted between lines. I can also put $some ($variables) here. EOF

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^2: Concatnate long statement
by varian (Chaplain) on Jul 04, 2007 at 07:16 UTC
    As here documents do introduce newlines in your string everywhere you start a new line they are not the same as a simple concatenation, behold:
    #!/perl my $foo = <<EOF; Would these two lines become one in a here document? EOF print "=$foo=\n";
    will output:
    =Would these two lines become one in a here document? =