2016-05-29 11 views
0

1つの配列の1つの列を別の配列に一致させ、それらの行を出力しようとしています。しかし、それは空白になる。どこが間違っているのか分かりません。個々の要素が印刷されています... いくつかの助けを探しています。コードは以下の通りです。 config_input.txtファイルは、以下のように見える必要な配列要素とperlの別の配列要素を一致させる

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 

以下のよう

#!/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 
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

$line =~ m/^$PU_file_line/ 

から、スクリプトの最後に条件あなたは何の出力を期待していますか? – choroba

+0

投稿されたスクリプトはコンパイルされません。実際のコードを投稿してください。 – jira

答えて

0

変更

$PU_file_line =~ /^$line/ 
+0

それは働いた。 Jiraに感謝します。私は今空白に取り組んでいます。しかし、私はそんなに愚かな間違いをしているのか分からなかった。 – Buddy

関連する問題