in reply to Extract multiple lists od Identifiers from a FASTA file

I think Bio::SeqIO from bioperl is probably still the recommended solution rather than rolling your own parser. That aside you’re missing parens on open when you create your output file so it’s not parsing the way you intend and you may not be seeing errors from there if you do have problems. Using the three arg open and parens would be better/current best practice.

my $outfile = qq{$path/$name.faa}; open( my $out_fh, q{>}, $outfile ) or die qq{problem writing to ‘$outf +ile’: $!};

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Extract multiple lists of Identifiers from a FASTA file
by hippo (Archbishop) on Aug 04, 2022 at 12:26 UTC
    you’re missing parens on open when you create your output file so it’s not parsing the way you intend

    This isn't wrong but equally the parens are not needed if or is used for control flow instead of ||. All three of these work (my preference in the comments)

    open( my $out_fh, q{>}, $outfile ) || die qq{problem writing to '$outf +ile': $!}; # OK open( my $out_fh, q{>}, $outfile ) or die qq{problem writing to '$outf +ile': $!}; # Better open my $out_fh, q{>}, $outfile or die qq{problem writing to '$outfile +': $!}; # Best

    The last of these is an idiom I use all the time (albeit with actual quotation marks rather than q/qq). I find that absence of unnecessary punctuation makes for clearer reading but recognise that not everyone sees it the same way. There is also autodie if you don't want or need to write your own error messages.

    All the rest of Fletch's advice is spot on. I'd also point you (joluito) to the Basic debugging checklist for help in finding out where things are going wrong.


    🦛

      I agree with hippo's choice, but... To paraphrase the introduction to the book "Perl Best Practices": The style is not very important. What is important is that you chose one that works for you and always use it.
      Bill