in reply to two vars from one string.

There are ways of naming vars with Dumper, but if all you want is different names,you can pass multiple values to Dumper at once.
print(Dumper(values(%hoh)));

Replies are listed 'Best First'.
Re^2: two vars from one string.
by mikejones (Scribe) on Mar 03, 2010 at 16:24 UTC
    I used Dumper to illustrate the data was in one var! My goal is to have the values in 2 separate variables?
    ## @hbas contains fcs0 fcs1 my %hoh; for my $hba (@hbas) { $hoh{$hba} = qx(/usr/bin/fcstat $hba|/usr/bin/grep -i node|/usr/bin/cut -f2 +-d:); } ### above gives me WWN strings while (my ($key, $val) = each %hoh) { print "$key =>\n\t$val\n"; print $val; } __OUTPUT__ fcs1 => 0x20000000C95A58AE 0x20000000C95A58AE fcs0 => 0x20000000C95C0379 0x20000000C95C0379
      But they are in two separate variables, $hoh{fcs0} and $hoh{fcs1}. What's the actual problem?
        thank you for replying again! my actual problem is my if clause in my foreach is not working for the second hash value.
        use strict; use warnings; use Data::Dumper; my @hbas; open (LSDEV, "/usr/sbin/lsdev |") or die $!; while (<LSDEV>) { if ( /^(fcs\d+)/ ) { push (@hbas, +(split)[0]); } } my %hoa; my $hba; for $hba (@hbas) { $hoa{$hba} = qx(/usr/bin/fcstat $hba|/usr/bin/grep -i "world wide port name"|/us +r/bin/cut -f2 -d:|sed s/0x//); } while (my ($key, $val) = each %hoa) { my ($str,$str1) = split / /, $hoa{$key}; print $str1,"\n"; foreach (<DATA>) { if ( /$str1/g ) { print "YES\n",qx(hostname),"\n",$key,$val,"\n"; print qx(/usr/bin/fcstat $key|head -n 7); print qx(/usr/sbin/lsmcode -cd $key); } } }
        __DATA__ 10000000C95C0379 10000000C9551477 10000000C95A58AE
        10000000C95CE93F 10000000C94056CD 10000000C9540D92 10000000C9502723 10000000C94FE5D7 10000000C948ACA7 10000000C959C9F9 10000000C956BD68 10000000C9619092 10000000C9639A5D "hba_FW.ksh" 146 lines, 2629 characters root@dxxxxxx:/export/resources/SOX/scripts> perl hba_FW.plx 10000000C95A58AE YES dunmpr01 fcs1 10000000C95A58AE FIBRE CHANNEL STATISTICS REPORT: fcs1 Device Type: FC Adapter (df1000fa) Serial Number: 1D63508268 Option ROM Version: 02881955 Firmware Version: T1D1.91A5 The current microcode level for fcs1 is 191105. 10000000C95C0379