in reply to Re^3: writing array element to a file
in thread writing array element to a file

Hi R! I modified the script as you suggested, while (my $line=<$in>) { if($line=~/^>/) { my @vettore=split(/\s+/, $line); print $out "$vettore1\n"; } } but the output file only contained 0, which is the number of the first line. What's I did wrong?

Replies are listed 'Best First'.
Re^5: writing array element to a file
by Random_Walk (Prior) on Apr 25, 2013 at 14:31 UTC

    It looks like you missed the square brackets around the array index in the print line.

    print $out "vettore1\n"; # bad print $out "vettore[1]\n; # good

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
      It wasn't the problem, brakets were there!
      my $infile = "rep_set_ass_tax.fna"; my $outfile = "seq_id.txt"; open my $in, '<', $infile or die "Can't read $infile; $!\n"; open my $out, '>>', $outfile or die "Can't read $outfile; $!\n"; while (my $line=<$in>) { if($line=~/^>/) { my @vettore=split(/\s+/, $line); print $out "$vettore[1]\n"; } }