In this post i will explain about the arrays in Perl.
When we want to declare an array variable we will use @ symbol so that perl can know that it is an array variable.
for ex
@array=(1,2,3);
Suppose we have the following statement:
@array=(1, 2 , 3 );
Then
print(@array,"\n");
What will be printed?
Elements of array will be printed without any spaces in between them
123
Now
print("@array\n");
What will be printed?
Elements of array will be printed with proper spacing
1 2 3
So if we will use @array in quotes ("") then proper spacing will be done by Perl regardless of the spaces in between elements. But if we will not use quotes then no spacing will be provided by Perl(As in case 1)
Program Code
When we want to declare an array variable we will use @ symbol so that perl can know that it is an array variable.
for ex
@array=(1,2,3);
Suppose we have the following statement:
@array=(1, 2 , 3 );
Then
print(@array,"\n");
What will be printed?
Elements of array will be printed without any spaces in between them
123
Now
print("@array\n");
What will be printed?
Elements of array will be printed with proper spacing
1 2 3
So if we will use @array in quotes ("") then proper spacing will be done by Perl regardless of the spaces in between elements. But if we will not use quotes then no spacing will be provided by Perl(As in case 1)
Program Code
#! /Perl/bin/perl
@array=(1, 2 , 3 );
print(@array,"\n");
print("@array\n");
@array=(1, 2 , 3 );
print(@array,"\n");
print("@array\n");
0 comments:
Post a Comment