Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:42:54+00:00 2026-06-18T20:42:54+00:00

I use this same bit of code with different files a couple times through-out

  • 0

I use this same bit of code with different files a couple times through-out the program without problems:

#if the info is part of a file
if($proteinIn =~  m/\.txt$/i){
    my $input_file = catfile('..', dataset => $proteinIn);

    open my $protein_file, '<', $input_file
        or die "couldn't open '$input_file': $!";
    while (my $protLine = <$protein_file>) {
        print $protLine."\n";
        $protLine =~ s/\s+\z//; # remove all trailing space
        $protein{$protLine} = 1;
    }
    close $protein_file;
}

When reading in a file containing this

Q5KDZ7_CRYNJ
Q2U9C0_ASPOR
Q2U048_ASPOR
G2Q3M9_THIHA
G2QAZ2_THIHA

the print statement “print $protLine.”\n”;” only prints the last line. In this case:

G2QAZ2_THIHA

the other example of this in my program reads every line of the files given

foreach my $tempFile(@fileList){
    my $input_file = catfile('..', dataset => $tempFile);

    open my $ps_file, '<', $input_file
        or die "couldn't open '$input_file': $!";
    while (my $line = <$ps_file>) {
        $line =~ s/\s+\z//; # remove all trailing space

        my @curLine = split /\t/, $line;
<the rest of the program>

The files opened by this code contain lines like:

>sp|Q6GZX4|001R_FRG3G Putative transcription factor 001R OS=Frog virus 3 (isolate Goorha) GN=FV3-001R PE=4 SV=1 MAFSAEDVLKEYDRRRRMEALLLSLYYPNDRKLLDYKEWSPPRVQVECPKAPVEWNNPPSEKGLIVGHFSGIKYKGEKAQASEVDVNKMCCWVSKFKDAMRRYQGIQTCKIPGKVLSDLDAKIKAYNLTVEGVEGFVRYSRVTKQHVAAFLKELRHSKQYENVNLIHYILTDKRVDIQHLEKDLVKDFKALVESAHRMRQGHMINVKYILYQLLKKHGHGPDGPDILTVKTGSKGVLYDDSFRKIYTDLGWKFTPL    FRG3G

Why is the first example of the code only printing the last line of the file?

Edit: Response to comment that problem is upstream in code; luckily my problem is near the beginning so here is everything before the problem code

When running the code, I used the command “perl regProt.pl “” “truePool.txt” “uniprot_sprot.dat” “fungi”

#!/usr/bin/env perl
use strict;
use File::Spec::Functions qw( catfile );

#use warnings;
#@author David Dziak

#A program for quick regex functions on uniprot data to test protein signatures
#my $max = 325783;
#my $cur = 0;
my $annotation;
my $fingerprint = $ARGV[0];
unless($fingerprint){
    $fingerprint = "[GASRK][KRVSG][RKVI][KRVI]x[ASCR]x[AST]x(0,45)[GATF]xxx[VLI]N[GKND]x(11,12)[RKL]x(16,18)[NDA]x(6)[GS]GGx(10)[AG][LIVM][GAS][KR][GASN][VLI]";#prosite s9

    #$fingerprint = "[GS]Gx(2)[GSA][QK]x(2)[SA]x(3)[GSA]x[GSTAV][KR][GSALVD][LIFV]";#prosite s9
    #$fingerprint = "[STDNQ]G[KRNQMHSI]x(6)[LIVM]x(4)[LIVMC][GSD]x(2)[LFI][GAS][DE][FYM]x(2)[ST]";#prosite s19
    #$fingerprint = "[RKHN][KSTR]X(3)[AVSCR]X(6)GXGX(0,23)X(25)GGGX(2)[GAS][QRKS]X(0,50)X(20)[APS]RX(5)[VSTA]XR";#s9
    #$fingerprint = "[GAR][RKHG][RKHNT][KSTR]X(3)[AVSCR][RASTHKQLP]X(5)[GPSTND]X[GPSTKDQ]X(4)[NDVGIT]X(0,60)G[GS]GX(2)[GSA][QRS]X(0,70)[QTRA][FWYETK][STAVH][KY][RK]";#s9
    #$fingerprint = "[RGWCKT]X(5)PX(3)[GARDENS]X(4)[VIL][HYF]XGX(7)[LIVMP]X(7)x[LFI][GASR][DEA][FYME]";#s19
}
$annotation .= $fingerprint;
#protein name to search
my $proteinIn = $ARGV[1];
my %protein;
#if the info is part of a file
if($proteinIn =~  m/\.txt$/i){
    my $input_file = catfile('..', dataset => $proteinIn);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:42:56+00:00Added an answer on June 18, 2026 at 8:42 pm

    I’m betting that your file for some reason has lines separated by \r, not \n.

    Try putting at the top:

    use Data::Dumper;
    $Data::Dumper::Useqq=1;
    

    and replacing the print with:

    print Data::Dumper::Dumper($protLine);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to update data in database table. Can reuse same code
I use this code to load the content from a different page into the
The same way i use this to detect when user scolled down the whole
i'm trying to use mongodb as a network wide configuration storage. This the same
<?php namespace foo; use My\Full\Classname as Another; // this is the same as use
use this website a lot but first time posting. My program creates a number
i use this line of code : [self parseXMLFileAtURL:url]; And i get this error
I use this script in two different servers: function curlGetFileInfo($url, $cookies=default){ global $_config; $ch
I use this code : MethodInvoker TileLoadCompleteMethodInvoker = delegate() { CleanStatusLabelTimer.Enabled = true; MemoryTextBox.Text
I am working on this bit of code that checks a line of actionscript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.