Whitespaces in Perl

PERLServer Side ProgrammingProgramming Scripts

A Perl program does not care about whitespaces. Following program works perfectly fine −

#!/usr/bin/perl
print    "Hello, world\n";

But if spaces are inside the quoted strings, then they would be printed as is. For example −

Example

 Live Demo

#!/usr/bin/perl
# This would print with a line break in the middle
print "Hello
         world\n";

Output

This will produce the following result −

Hello
      world

All types of whitespace like spaces, tabs, newlines, etc. are equivalent to the interpreter when they are used outside of the quotes. A line containing only whitespace, possibly with a comment, is known as a blank line, and Perl totally ignores it.

raja
Published on 28-Nov-2019 07:38:48
Advertisements