Hey all,
I am reading in from a file with the following fields:
Name|Flag|Function|ID
P_1|0|LC|0|
P_1|1|LC|1|
P_2|1|LC|2|
P_2|0|LC|3|
P_2|0|LC|4|
P_12|0|LC|0|
P_12|0|LC|1|
P_12|0|LC|2|
P_12|0|LC|3|
I am trying to read only those names where the flag is set to "0" and NO "1's" are assocatied to that name. So for the above file, I want to grab all records for P_12 and ignore P_1 and P_2.
#!/usr/bin/perl
use strict;
open IN,"< ./file.xls" || die "Cannot open file.xls
$!)"; while (my $line = <IN>) {
if ($line =~ /^Name/i) {
next;
}
my ($Name,$Flag,$Function,$ID) = split (\|/,$line);
my @name = $Name;
foreach my $name (sort @name) {
if ($Flag == 1) { next; }
print "$name, $Flag, $Function, $ID\n";
}
} close IN;
This gives me the next record but for same Name where the Flag=0.
I am trying another approach, using hashes, but wanted to check if there is an easier way.
Thank you.
I am reading in from a file with the following fields:
Name|Flag|Function|ID
P_1|0|LC|0|
P_1|1|LC|1|
P_2|1|LC|2|
P_2|0|LC|3|
P_2|0|LC|4|
P_12|0|LC|0|
P_12|0|LC|1|
P_12|0|LC|2|
P_12|0|LC|3|
I am trying to read only those names where the flag is set to "0" and NO "1's" are assocatied to that name. So for the above file, I want to grab all records for P_12 and ignore P_1 and P_2.
#!/usr/bin/perl
use strict;
open IN,"< ./file.xls" || die "Cannot open file.xls
if ($line =~ /^Name/i) {
next;
}
my ($Name,$Flag,$Function,$ID) = split (\|/,$line);
my @name = $Name;
foreach my $name (sort @name) {
if ($Flag == 1) { next; }
print "$name, $Flag, $Function, $ID\n";
}
} close IN;
This gives me the next record but for same Name where the Flag=0.
I am trying another approach, using hashes, but wanted to check if there is an easier way.
Thank you.