Neeraj wrote:
Hi,

I am new to Perl and perplexed with output of printing entire Array vs
printing each element

     +4  ## check Array vis-a-vis List
     +5
     +6  @arr = qw<hello happy new year 2013>;
     +7  print "my array is : @arr \n";
     +8
     +9  ## lets print in a loop
    +10  my $i = 0;
    +11  while ($i<= $#arr)
    +12  {
    +13   print $arr[$i];
    +14   $i += 1;
    +15  };
    +16  print "\n";

In Perl that is usually written as:

## lets print in a loop
for my $i ( 0 .. $#arr )
{
 print $arr[$i];
}

Or as:

## lets print in a loop
for my $i ( @arr )
{
 print $i;
}

Or simply:

## lets print an array
print @arr;




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to