kindly explain, why this issue comes
my data file
DATA----1
DATA----2
DATA----3
DATA----4
DATA----5
DATA----6
DATA----7
SAMPLE----1
SAMPLE----12
SAMPLE----13
SAMPLE----2
SAMPLE----3
SAMPLE----4
SAMPLE----5
OTHER----1
OTHER----2
OTHER----3
where I need entire line which start with DATA and SAMPLE to an array and an another array should have content which start with SAMPLE end with two digit number
I have got output with following script
use strict;
use warnings;
open(FH, "di.txt");
my @file = <FH>;
close(FH);
my @arr2 = grep { $_ =~ m/^SAMPLE.+\d\d$/g } @file; ## this array prints
my @arr1 = grep { $_ =~ m/^DATA|^SAMPLE/g } @file;
print @arr1,"\n\t~~~~~~~~~~~\n\n",@arr2;
First writen as
use strict;
use warnings;
open(FH, "di.txt");
my @file = <FH>;
close(FH);
my @arr1 = grep { $_ =~ m/^DATA|^SAMPLE/g } @file;
my @arr2 = grep { $_ =~ m/^SAMPLE.+\d\d$/g } @file; ## this doesn't print
print @arr1,"\n\t~~~~~~~~~~~\n\n",@arr2;
while run this one, prints only @arr1
what would be the reason @arr2 don't print
@arr2.$after\d, you will get desire output keeping array in any order.open $fh, "<", "di.txt" or die "Unable to open : $!";