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
输出即将空白。
条件你期望的输出? – choroba
发布的脚本将不会编译。发布一个真实的代码。 – jira