in reply to Re^3: two vars from one string.
in thread two vars from one string.

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

Replies are listed 'Best First'.
Re^5: two vars from one string.
by ikegami (Patriarch) on Mar 03, 2010 at 21:37 UTC
    • if (/.../g) doesn't make sense in theory — why would check if a string matches a pattern, then check some more? — and it's buggy in practice.

    • for (<...>) loads the entire file into memory. You could just as easily process the file a line at a time using while (<...>).

    • DATA will never produce anything after the first pass of the outer loop, since the first pass read DATA until its EOF. Place the contents of DATA into an array and iterate over the array instead.

    • You're evaluating qx(hostname) countless time when once would do.