On 2019-10-29 7:48 p.m., 刘东 wrote:
Dear every one:

Hello.

I try to write a perl script to delet the content of file carp01_1_both.txt as 
same as from another file carp-carp01_TKD181002053-1_1_sg.txt, so to get a new 
file from file carp-carp01_TKD181002053-1_1_sg.txt but excluding file 
carp01_1_both.txt. However, when I run this scrip, it does not work, and 
display the information as follows:
...

Semicolon seems to be missing at carp01_1_both.txt line 44993.


syntax error at carp01_1_both.txt line 1, near "979:"

These messages say that perl is trying to interpret your data file as if it were a Perl program.


perl script:
#!/usr/bin/perl -w
open(NAME,"<$ARGV[0]")|| die;
open(SECON,"<$ARGV[1]")|| die;
open(SELEC,">$ARGV[2]")|| die;
$name = "";
%pair = ();

while(<NAME>){
      chomp;
      my @line = split("\t",$_);
         $name = $line[0];
         $pair{$name} = 1;
}

while(my $li = <SECON>){
     chomp($li);
     my  @line = split("\t",$li);
         $name = $line[0];
     my  $cont = $li;
    if (exists $hash{$name}) { # if current read appeared before
         next;
         } else { # if it haven't been read before
         print SELEC "$cont\n";
  }
}

close NAME;
close SECON;
close SELEC;

#!/usr/bin/perl
use warnings;
use strict;

open my $NAME, '<', $ARGV[ 0 ] or die "Cannot open '$ARGV[0]' because: $!";
open my $SECON, '<', $ARGV[ 1 ] or die "Cannot open '$ARGV[1]' because: $!";
open my $SELEC, '>', $ARGV[ 2 ] or die "Cannot open '$ARGV[2]' because: $!";

my %pair;

while ( <$NAME> ) {
    my ( $name ) = split /\t/;
    $pair{ $name }++;
    }

while ( <$SECON> ) {
    my ( $name ) = split /\t/;
    print { $SELEC } $_ unless exists $pair{ $name };
    }

close $NAME;
close $SECON;
close $SELEC;

__END__


John

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to