ciwei wrote:
HI, a quetion from a newbie to perl.
I have a program that extract some fields:

#!/usr/bin/perl -w

use strict;

my ( $host, $hba, $storage, $fa ,$initiator , $target ) ;

It appears that you don't really need those variables in file scope.

my %wwn = ();

while ( <DATA> ) {
 next unless /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w+)[_-](\w+)\s+ ...
WWN: \d\d\d\d\w{12}/;

That pattern will not match because <DATA> reads one line at a time and 'WWN: \d\d\d\d\w{12}' is on a different line then the rest of the pattern.


( $host, $hba, $storage, $fa ) = /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w
+)[_-](\w+)\s+/;

You don't need to use the same pattern twice:

    next unless /^\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w+)[_-](\w+)$/;
    my ( $host, $hba, $storage, $fa ) = ( $1, $2, $3, $4 );


   print "HOST = $host , HBA = $hba , storage = $storage, FA = $fa
\n";

   $initiator = $host."-".$hba;
   $target  = $storage."-".$fa;

   push  $wwn{$initiator}, $1   if /WWN:\s+(1000\d{12})/;
   push  $wwn{$target}   , $1   if /WWN:\s+(500\d{13})/;

You need to supply an array as the first argument to push(). Also, the test is not needed. And it looks like the digits are hexadecimal so \d won't match.

  push @{ $wwn{ "$host-$hba"   } }, /^\s+WWN:\s+(1000[0-9a-fA-F]{12})$/;
  push @{ $wwn{ "$storage-$fa" } }, /^\s+WWN:\s+(500[0-9a-fA-F]{13})$/;


}

__DATA__
             DEV01-HBA0_DMX1-13CA
              WWN: 10000000C934A35B
              WWN: 5006048ACAFE1E4C
             DEV01_HBA0_CX-SPA_P0
              WWN: 10000000C934A35B
              WWN: 500601601060007E
             TEST01_HBA1_STK_TAPES1
              WWN: 100000E002239270
              WWN: 500104F000619193
              WWN: 500104F00061918D
              WWN: 500104F000619190
              WWN: 500104F00061919D


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

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


Reply via email to