Javatpoint Logo
Javatpoint Logo

Perl print() and say()

Perl print() function is one of the most commonly used function by the Perl users. It will print a string, a number, a variable or anything it gets as its arguments.

Perl print syntax is given below:

Perl print example

Let's see a simple example of Perl Print() function.

Output:

Welcome to JavaTpoint!! This is our Perl tutorial!!

The above output prints both the sentences in the same line. To print them in different lines, we can use "\n" new line character in print function.

Perl print example with '\n'

The '\n' character is used to print a new line. It is used at the end of the print function.

Output:

Welcome to JavaTpoint!! 
This is our Perl tutorial!!

Perl print Example with Variables

To print the variables value, you need to pass the variable in print function.

Output:

Welcome to JavaTpoint!!
JavaTpoint provides you all type of tutorials!!

Here, we have defined a variable $site. We have passed this variable in the string which prints its value in the output.

Perl print Example with Single and Double Quotes

Perl print function does not interpolate inside single quotes. It means it prints the characters inside single quote as it is. It neither evaluates the variable?s value nor does it interpret the escaping characters.

When the above example runs inside a single quote, you will notice the following changes.

Output:

Welcome to $site!! \n$site provides you all type of tutorials!!\n

In the output, variable $site is printed as it is. Its value is not evaluated. The new line character is also not interpreted.

Perl say()

The say() function is not supported by the older perl versions. It acts like print() function with only difference that it automatically adds a new line at the end without mentioning (\n).

Note: you need to mention the version in your script to use say() function. Without using version, you?ll get error in the output.

Perl say() syntax is given below:

Perl say() Example

Let's see a simple example of perl say function.

Output:

Welcome to JavaTpoint!! This is our Perl tutorial!!	

The above output prints both the sentences in different lines without using the new line character. And here we have used use 5.010 to support say function.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA