Multiline Strings in Perl

PERLServer Side ProgrammingProgramming Scripts

If you want to introduce multiline strings into your programs, you can use the standard single quotes as below −

Example

 Live Demo

#!/usr/bin/perl
$string = 'This is
a multiline
string';
print "$string\n";

Output

This will produce the following result −

This is
a multiline
string

You can use "here" document syntax as well to store or print multiline as below −

Example

 Live Demo

#!/usr/bin/perl
print <<EOF;
This is
a multiline
string
EOF

Output

This will also produce the same result −

This is
a multiline
string
raja
Published on 28-Nov-2019 09:12:15
Advertisements