Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-20-2008, 04:45 AM   #1
LQ Newbie
Registered: Jan 2008
Posts: 27

Rep: Reputation: 15
Question printing array contents after "push" of elements gives a different output in PERL


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.

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

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.

~ gaynut
Old 08-20-2008, 05:04 AM   #2
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
man perlfunc
push returns the number of elements in the array following the completed "push".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Feeding the output of "diff" or "cat" command to dpkg --purge kushalkoolwal Debian 9 06-19-2008 08:27 AM
trimming perl array elements homey Programming 7 02-17-2008 04:48 PM
K3b: - Howto re-dock "Directories" and "Contents" windows back into the main window? hagies Linux - Software 4 04-26-2006 09:38 AM
Deleting elements from array in perl with splice signalno9 Programming 2 08-16-2005 11:57 PM
perl - get number of elements in an array AM1SHFURN1TURE Programming 3 03-07-2005 04:59 PM

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration