Hash Issue or Understanding

From: Bruce Phillip (Bruce_Phillip_at_emc.com)
Date: 10/30/03


To: beginners@perl.org
Date: Thu, 30 Oct 2003 03:17:11 -0500

Hi,

 

   For those of you who helped me with my earlier scripts. Thanks.

 

   But I have a further problem in understanding something. Using

   The following declaration:

 

my %commands = ('sol'=>{'hostname' =>'uname -n',

                                        'os' =>'uname -s',

                                        'osver' =>'uname -r',

                                         'osrel' =>'cat /etc/release
| awk \'{print $3}\'',

                                         'srvtype' =>'uname -p',

                                         'srvmodel' =>'uname -i | cut -f2
-d ","',

                                         'memory' =>'prtconf | grep
Memory | awk \'{print $3}\'',

                                         'cpu' =>'psrinfo | awk
\'{print $1}\' | wc -l'}

                                );

 

 I have my code now as followed:

 

foreach $items (keys %commands) {

  foreach $CMD (keys %{$commands{$items}}){

    print "Command: $CMD \n";

    $results=(&get_response($commands{$items}{$CMD}))[0];

    print OUT_FH "$results,","";

  }

}

 

The output works but it not in the order I expected:

I expected my output to be:

hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory
Size, Total CPU's.

 

But what I got was:

 

Model, Server Type, cpu, Release, hostname, OS, Memory Size, Version

 

It seems to me the hash started almost at the bottom of the list instead of

With the hostname and work it way down. Is there any way to force the

Order other than maybe specifying the array itself?.

 

Phillip Bruce
ISC Consultant, System Architect
Location: Dublin, CA
* Cell: 408-476-8658
* Office: 925-560-7853
AIM: OkieUnix

 



Relevant Pages

  • Re: Hash Issue or Understanding
    ... >hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory ... >It seems to me the hash started almost at the bottom of the list instead of ...
    (perl.beginners)
  • RE: Hash Issue or Understanding
    ... Subject: Hash Issue or Understanding ... >hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory ...
    (perl.beginners)
  • Re: Errno 25 ENOTTY then SIGSEGV, socket on accept call? Help.
    ... the problem (you might even find the cause of the segfault yourself ... Your compiler should tell you so. ... you probably didn't allocate enough memory ... If it isn't 'hostname' isn't some- ...
    (comp.unix.programmer)
  • Re: commands to manipulate files
    ... In both cases (while read loop vs awk), ... process running at a time, so it shouldn't make a big ... measuring performance as it may take into account the time spent ... pages of code or data around in between cache, memory, ...
    (comp.unix.shell)
  • Re: Newbie: Question about Locale
    ... I am running a 400mhz and 128 meg memory and it is not slow. ... A big factor I have seen in slow gui problems have been the hostname ... nameserver 204.127.202.34 ...
    (alt.os.linux)