On Wednesday 29 Oct 2003 7:35 pm, [EMAIL PROTECTED] wrote: > Hi, > > It has come to my attention that I need a little understanding > of what I'm doing here. Gary has provide some overview but not > Technical detail as I would like to have. That isn't his fault. > I admire his feedback for sure. > > The code is obvious using hash. This is something I think I need > to get a little more clarity on. I would appreciate some feedback > Using the declaration I've setup here. > > # > # List of Operating Systems > # > my %whichos=('SunOS' =>'sol', > 'Aix' =>'aix', > 'HP-UX' =>'hpux', > 'Micorsoft'=>'W2K'); > > # > # List of Commands OS specific > # > > 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'} > ); > > With my declared array of whichos and commands. I need to understand > What is considered the value and what is consider the key. > > In whichos I think SunOS is the key and the value is sol. > In commands I think sol is the key and then a secondardy key is hostname > with the value of uname -n. > > To me it looks as though whichos is a dual deminsioned array while commands > Is a 3 x 3 deminsioned array. > > Have I got this correct so far or am I'm off my rocker? > > So if I'm going to search thru this array maybe use the following: > > Foreach $OS (key $whichos){ > Foreach $CMD {key $command{$OS}){ > Print $CMD; <=== This should list out the values in commands array. > } > } > > I think once I understand that then it be easier for me to understand how > To assign that $CMD variable properly. Thanks for the feedback.
Hi Phil, (I'll answer your other post when I can see what's wrong). You're pretty close. You are right about the %whichos hash, SunOS is the key pointing to 'sol' which is the value. However, you're not quite there with the %commands. You're right in that 'sol' is a key, but not about the data. The data is actually a pointer anonymous hash which then itself contains key/value pairs, 'os' being the key and 'uname -n' being the value. your loop above would be: (not it's 'keys' not 'key', and because you're accessing whichos as a hash and not a scalar, you need to use the %) foreach my $OS (keys (%whichos) { # loop through all whichos foreach my $cmd (keys %commands { # loop through commands for one OS print "$cmd for $OS is '",$commands{$OS}{$cmd},"'.\n"; } } example output would be: memory for sol is 'prtconf | grep Memory | awk \'{print $3}\'. to explain the $commands{$OS}{$cmd}: $ means that we wish to extract a scalar commands{$OS} gives us a pointer to the hash containg the commands for that OS {$cms} gives us the hash value for the key $cmd in that hash HTH Gary -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]