A
Andrea Spitaleri
Hi
I have a file and I would like to remove from it the lines that match
the values from an array.
Here is the code that I unsuccessfully tried:
#!/usr/bin/perl
use warnings;
use strict;
open (FILE,"<$ARGV[0]") or die "$!";
my @h = ("H","N");
while (my $line=<FILE>){
chomp $line;
foreach my $i (@h){
next if ($line=~ / +$i/);
print "$line\n";
}
}
and the file is something like that:
2 C2 -0.4158 0.5051 -0.2805 C.3 1 UNK
0.2800
3 H3 -0.0655 0.8795 0.6861 H 1 UNK
0.0000
13 H13 -2.5997 0.4032 -0.4902 H 1 UNK
0.0000
14 N14 -2.0421 -0.8226 1.0724 N.2 1 UNK
0.0476
15 C15 -1.9418 -2.1366 1.4487 C.2 1 UNK
0.0365
1 O1 -0.4981 1.6455 -1.1635 O.3 1 UNK
-0.6800
2 C2 -0.4158 0.5051 -0.2805 C.3 1 UNK
0.2800
................
Swapping next with print "found $i" after the foreach I figured out
that the loop is working properly (it matches that array values) but
doesn't next.
What is it wrong????
thanks
regards
and
I have a file and I would like to remove from it the lines that match
the values from an array.
Here is the code that I unsuccessfully tried:
#!/usr/bin/perl
use warnings;
use strict;
open (FILE,"<$ARGV[0]") or die "$!";
my @h = ("H","N");
while (my $line=<FILE>){
chomp $line;
foreach my $i (@h){
next if ($line=~ / +$i/);
print "$line\n";
}
}
and the file is something like that:
2 C2 -0.4158 0.5051 -0.2805 C.3 1 UNK
0.2800
3 H3 -0.0655 0.8795 0.6861 H 1 UNK
0.0000
13 H13 -2.5997 0.4032 -0.4902 H 1 UNK
0.0000
14 N14 -2.0421 -0.8226 1.0724 N.2 1 UNK
0.0476
15 C15 -1.9418 -2.1366 1.4487 C.2 1 UNK
0.0365
1 O1 -0.4981 1.6455 -1.1635 O.3 1 UNK
-0.6800
2 C2 -0.4158 0.5051 -0.2805 C.3 1 UNK
0.2800
................
Swapping next with print "found $i" after the foreach I figured out
that the loop is working properly (it matches that array values) but
doesn't next.
What is it wrong????
thanks
regards
and