Monday, July 25, 2011

perl array newline



#!/usr/bin/perl
$"="\n";
@array1=("hello","great","awesome","wonderful");
print "@array1";

Here the special variable $" is used which is the separator used between the list elements when an array variable is interpolated into double quotes.Normally this value is set to default as space.Here i have made this value expilictly as "\n" to make it print in a newline.

Output:

G:\perl_programs>perl perl_array_print.pl
hello
great
awesome
wonderful
G:\perl_programs>perl perl_array_print.pl


print with newline perl



$\="\n";
print "@hell";
print "marvellous";
print "great";
print "asasasasas"."ffffff"."fdifdfd";
print "awesome";

Here the special variable "$\" is used which is added as  the invisible element to end of the print statement .Normally it is empty it can be assigned "\n" if you want to print everytime in a newline.

output:

G:\perl_programs>perl perl_print.pl

marvellous
great
asasasasasfffffffdfdfd
awesome

G:\perl_programs>