LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-16-2008, 01:08 PM   #1
s0l1dsnak3123
LQ Newbie
 
Registered: Jan 2008
Distribution: Ubuntu Hardy Heron
Posts: 18

Rep: Reputation: 0
[perl] copying an array element into another array


hi there.

I want to copy all array elements from $cpu->load[] to @load. I have tried the following without any success:

Code:
my $info = Sys::Info->new;
my $cpu  = $info->device( 'CPU' );

my @load;
foreach ($cpu->load) {
push(@load, $_);
print $_ . "\n";
}
Is there another way for me to do this?

thanks,

s0l1dsnak3123
 
Old 05-16-2008, 06:56 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Your question does not make sense. $cpu->load is a subroutine, not an array. The subroutine always returns a scalar. The value returned depends on the subroutine’s first parameter. According to this, the valid parameters are 0, 1, or 2 for the load in the last 1, 5, or 10 minute interval respectively.

So if you want to get all the values, you can map the specified values to the subroutine with said values as a parameter. E.g.,
Code:
my @load = map $cpu->load($_), 0, 1, 2;
Or, as a hash,
Code:
my %load_by_minute;
@load_by_minute{1, 5, 10} = map $cpu->load($_), 0, 1, 2;
 
Old 05-17-2008, 01:47 AM   #3
s0l1dsnak3123
LQ Newbie
 
Registered: Jan 2008
Distribution: Ubuntu Hardy Heron
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks alot, it works perfectly now
 
  


Reply

Tags
array, copy, perl


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
Find whether an element exists in an array. Sherlock Programming 8 06-21-2007 07:07 AM
index of an element in the array ? thelonius Programming 1 09-24-2005 12:41 PM
number of element in a array of pointer? os2 Programming 7 03-09-2005 11:50 AM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM
C++ Six Element Array petercool Programming 2 08-20-2003 11:08 AM


All times are GMT -5. The time now is 03:55 AM.

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