LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   printing array contents after "push" of elements gives a different output in PERL (https://www.linuxquestions.org/questions/programming-9/printing-array-contents-after-push-of-elements-gives-a-different-output-in-perl-664001/)

gaynut 08-20-2008 03:45 AM

printing array contents after "push" of elements gives a different output in PERL
 
hi,

i have a doubt in printing the contents of an array after doing
"push" on it.
The question goes as follows.


@arr=qw(1 2 3 4 5);
print @arr;
print "@arr";

The above yields 1 2 3 4 5
1 2 3 4 5 which is nothing but contents of the array.

suppose,
@arr=qw(1 2 3 4 5);
@arr=push(@arr,"a");

print @arr;
print "@arr";


The above yields the array count with o/p as 6 6 .

Could somebody tell why is it so.
Also tell me how to get the contents of the array?

I tried opening a foreach loop for the array and tried printing element by element.
This again yielded the array count than its contents.
Ur explanation is highly appreciated.


Thanks
~ gaynut

burschik 08-20-2008 04:04 AM

Code:

man perlfunc
push returns the number of elements in the array following the completed "push".


All times are GMT -5. The time now is 02:06 AM.