Perl Print Multiple Lines: Methods

In Perl, you can use the print statement to output multiple lines of content. There are two methods to achieve this.

  1. Use the newline character “\n” in the print statement to separate each line of content, for example:
print "This is line 1\n";
print "This is line 2\n";
print "This is line 3\n";
  1. Use a here document to output multiple lines of content. A here document is a special syntax structure that allows you to define multi-line strings in your code. For example:
print <<END;
This is line 1
This is line 2
This is line 3
END

In the example above, END serves as a marker to end the here document, and you can use any identifier you want. The content between this marker will be output as a multi-line string.

bannerAds