Wiggins,

 I tried that suggestion you have and got the
 The following message:

C:\Perl\Accenture>perl test2.pl
Can't use string ("sol") as a HASH ref while "strict refs" in use at
test2.pl line 59.

That is using your suggestion:

foreach my $OS (keys(%commands)) {
   while (my ($key, $command) = each (%$OS)) {
      print "$key running $command\n";
   }
}
-----Original Message-----
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 31, 2003 12:33 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Hash Issue



> 
> Hi,
> 
>  
> 
>   I've been playing around with the Tie::IxHash module.
> 
>  
> 
>  Here is my part of my code:
> 

It appears to be lacking, use strict and use warnings these will help
you track down on your own your errors....

>  
> 
> tie my %commands, "Tie::IxHash";
> 
>  
> 
> %commands = ('sol'=>{'hostname'  =>'uname -n', 
> 
>                              'os'             =>'unamed -s',
> 
>                              'over'          =>'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 haven't used the tied hash much, but assuming it works as a regular
has as it should...

> 
>  
> 
> foreach $OS (keys %commands){
> 

Right here $OS contains a hash reference to the inner hash for the
particular operating system...

>   print "OS: $OS \n";
> 
>   while (( $OS, $CMD ) = each %commands ) {
> 

Right here you are eaching over %commands inside a foreach on keys which
is probably not what you want, and is probably doing screwy things, like
resetting the position indicator of the hash.... And you are also
clobbering your preset $OS which means you can no longer access that
particular hash to loop over.

>     print "$OS Commands are $items .\n";    ***** 
> 

Where did $items come from in the first place.  

>   }
> 
> }
> 
>  
> 
> If I change the $items variable in the print statement where the
asterisk is
> to $CMD I get nothing but a hex value output. Has anyone have a suggestion
> what I'm doing wrong. 
> 

How about:

foreach my $OS (keys(%commands)) {
   while (my ($key, $command) = each (%$OS)) {
      print "$key running $command\n";
   }
}

I was thinking that your use of the tied hash was to get the commands to
run in order rather than the OS's (maybe I missed part of this
discussion) if that is the case the inner hashes must be the tied
variants, rather than the outer.....

perldoc perllol
perldoc perldsc
perldoc perlreftut
perldoc perlref

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to