Smith, Derek wrote:
> My hash creations are not working as I expected:  %hash = ( @mir,
> @mir2 );
> 
> Why?
> 
        To populate a hash requires two fields: Key and data. What you are 
assuming is that it will take one from @mir and one from @mir2 which is a wrong 
assumption. Yes the second works because you do take the key and data, but one 
from each array.

        Could do something like:

        while ( @mir ) {
           $hash{shift(@mir)} = shift(@mir2);
       }

Did a quick test and does work.

Wags ;)

> But do work at %hash = ( $mir[0], $mir2[0] );
> 
> 
> 
> Obviously I need the entire arrays and their associated key/value
> pairs, 
> and have tried various methods unsuccessfully from Programming Perl CD
> such as array of hashes.
> 
> The end result for my key/value pair should look like
> 
> 
> 
> Mirror copies               1                   : /dev/vg00/lvol3
> 
> 
> 
> Which is the printed output of the individual element assignment as
> %hash = ($mir[0],$mir2[0]);
> 
> But cannot get %hash = (@mir,@mir2); to work.  Plz help.
> 
> 
> 
> my (%hash,@mir,@mir2)    = ();
> 
>     my ($key2,$value2)       = 0;
> 
>     foreach my $lv (@lvs) {
> 
>         push @mir => (grep /mirror/i, `lvdisplay $lv`);
> 
>         push @mir2 => (grep s/^LV Name\s*//, `lvdisplay $lv`);
> 
>         chomp (@mir,@mir2);
> 
>     }
> 
> 
> 
>     #%hash = (@mir,@mir2);                   ## This does not work the
> way I expect, so I tried the foreach in the next line.
> 
>     foreach (@mir) {
> 
>         foreach (@mir2) {
> 
>             ($key2,$value2) = [ split ];
> 
>             $hash{$key2}    = $value2;
> 
>         }
> 
>     }
> 
> 
> 
>     while (($key2,$value2) = each %hash) {
> 
>     #    ($key2,$value2) = [ split ];
> 
>         print "$key2\t:$value2";
> 
>     }
> 
> 
> 
> 
> 
> 
> 
> Derek Bellner Smith
> 
> Unix Systems Engineer
> 
> Cardinal Health Dublin, Ohio
> 
> 614-757-5000 Main
> 
> 614-757-8075 Direct
> 
> 614-757-8120 Fax
> 
> [EMAIL PROTECTED]
> 
> 
> 
> 
> Cardinal Health -- Working together. For life. (sm)
> _________________________________________________
> 
> This message is for the designated recipient only and may contain
> privileged, proprietary, or otherwise private information. If you
> have received it in error, please notify the sender immediately and
> delete the original. Any other use of the email by you is prohibited.
> 
> Dansk - Deutsch - Espanol - Francais - Italiano - Japanese -
> Nederlands - Norsk - Portuguese - Svenska:
> www.cardinalhealth.com/legal/email  


**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to