2016-05-29 98 views
0

我試圖將一個數組單列匹配到另一個列中並打印這些行。但它是空白的。不知道它出錯的地方。個別元素正在打印... 尋求一些幫助。代碼如下:將所需的數組元素與perl中的另一個數組元素進行匹配

#!/usr/bin/perl 
use strict; 
use warnings; 
#use File::Find; 

#!/usr/bin/perl 
use strict; 
use warnings; 

# Define file names and its location 
my $input = $ARGV[0];  # requires input raw DS8K PU file 

############################################################################################ 
# Section to read config file and extract volumes of user inserted volumegroup 
############################################################################################ 
my $input_PU_config = $ARGV[1]; # requires input config file 

my @vg_vol_id; # defining variable for config file 
my @interval_data = ('start_time','length'); 

print "\nEnter the volume group number you need to work upon: "; # I insert number as 8 and it greps "V8" required line from the config file 
chomp (my $vol_grp_number = <STDIN>); 

open (CONFIG_INFILE,"$input_PU_config_file") or die "Could not open: $!"; 
while (<CONFIG_INFILE>) 
    { 
    if (/ FB 512/&& (/ V$vol_grp_number,/ || /,V$vol_grp_number/||/V$vol_grp_number /)) ## If device is part of multiple VG 
     { 
     my @volume_id = split(/\s+/,$_); 
     push @vg_vol_id, "0x$volume_id[1]"; 
     #print "0x$volume_id[1]\n"; 
     } 
    } 
unshift @vg_vol_id,@interval_data; 
#print "@vg_vol_id\n"; 
close (CONFIG_INFILE); 
############################################################################################ 
# Grab the only vols stats for different intervals and put it in a file 
open (INFILE,"$input_file") or die "Could not open: $!"; 
open (OUTFILE,">$output_file") or die "Could not open: $!"; 
while (<INFILE>) 
    { 
    if (/^volume stats/ .. /^$/) 
     { 
     print (OUTFILE "$_"); 
     } 
    } 
close (INFILE); 
close (OUTFILE); 
############################################################################################### 
# the parsed file is stored as @PU_file array element 
open (PARSED_PU_FILE,"$output_file") or die "Could not open parsed file: $!"; 
my @PU_file = <PARSED_PU_FILE>; 
############################################################################################### 
foreach my $PU_file_line (@PU_file) 
    { 
      #chomp ($PU_file_line); 
      #print "$line\n"; 
      foreach my $line (@vg_vol_id) 
        { 
          chomp ($line); 
          #print "$line\n"; 
          if ($line =~ m/^$PU_file_line/) 
          { 
            print "$PU_file_line\n"; 
          } 
        } 
        #print "======================\n"; 
    } 
close (PARSED_PU_FILE); 

的input.txt的文件看起來如下

unwanted lines 
unwanted lines 
unwanted lines 
unwanted lines 

volume stats 
start_time 1 
length  2 
-------- 
ID 
0x00a,1,2,3,4 
0x00b,11,12,13,14 
0x00c,21,22,23,24 

unwanted lines 
unwanted lines 
unwanted lines 

volume stats 
start_time 2 
length  2 
-------- 
ID 
0x00a,31,32,33,34 
0x00b,41,42,43,44 
0x00c,51,52,53,54 

unwanted lines 
unwanted lines 
unwanted lines 

volume stats 
start_time 3 
length  2 
-------- 
ID 
0x00a,61,62,63,64 
0x00b,71,72,73,74 
0x00c,81,82,83,84 

unwanted lines 
unwanted lines 
unwanted lines 

的config_input.txt文件看起來如下;

unwanted lines 
unwanted lines 
EP0Vol1000 00a Online Normal Normal  2107-900 FB 512 P0  Standard  DS  68.0   - 142606336 V4,V9   142606336 rotateexts PG0  RG0 
EP0Vol1000 00b Online Normal Normal  2107-900 FB 512 P0  Standard  DS  68.0   - 142606336 V4,V8   142606336 rotateexts PG0  RG0 
EP0Vol1001 00c Online Normal Normal  2107-900 FB 512 P0  Standard  DS  68.0   - 142606336 V4,V8   142606336 rotateexts PG0  RG0 
EP0Vol1001 00d Online Normal Normal  2107-900 FB 512 P0  Standard  DS  68.0   - 142606336 V4,V10   142606336 rotateexts PG0  RG0 
unwanted lines 
unwanted lines 

輸出即將空白。

+1

條件你期望的輸出? – choroba

+0

發佈的腳本將不會編譯。發佈一個真實的代碼。 – jira

回答

0

更改在腳本的末尾,從

$line =~ m/^$PU_file_line/ 

$PU_file_line =~ /^$line/ 
+0

它的工作。謝謝吉拉。我現在正在研究空白空間。但是,不知道我犯了這樣一個愚蠢的錯誤。 – Buddy

相關問題