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 8768775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:09:08+00:00 2026-06-13T17:09:08+00:00

Curious if I can get a little help here. I’m a perl newbie, and

  • 0

Curious if I can get a little help here. I’m a perl newbie, and can’t figure out how to convert the following code into something a bit more useful for my analysis.

This code presently takes the 1st and 4th column from a user supplied list of data files and puts them together.

What I’d like my code to do, for each row of the “current output” generated by this code (see below), is make a sum of these 4th column values (filea, fileb, filec). Not quite sure how to implement this…

Current Output:

filea   fileb  filec

entrya  | 0 |10.2 | 0
entryb  | 0 | 0.0 | 1     
entryc  | 8 | 57.0| 46       

desired output

         sum
entrya | 10.2
entryb | 1
entryc | 111

current code looks like this:

main: {


my %data;

foreach my $file (@rsem_files) {

    open (my $fh, $file) or die "Error, cannot open file $file";
    my $header = <$fh>; # ignore it
    while (<$fh>) {
        chomp;
        my @x = split(/\t/);
        my $acc = $x[0];
        my $count = $x[4];
        $data{$acc}->{$file} = $count;
    }
    close $fh;
}

my @filenames = @rsem_files;
foreach my $file (@filenames) {
    $file = basename($file);
}


print join("\t", "", @filenames) . "\n";
foreach my $acc (keys %data) {

    print "$acc";

    foreach my $file (@rsem_files) {

        my $count = $data{$acc}->{$file};
        unless (defined $count) {
            $count = "NA";
        }

        print "\t$count";

    }

    print "\n";

}


exit(0);
}
  • 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-13T17:09:09+00:00Added an answer on June 13, 2026 at 5:09 pm

    Alter the @rsemfiles loop:

    # create $total variable outside loop
    my $total = 0; 
    foreach my $file (@rsem_files) {
        my $count = $data{$acc}->{$file};
        # change unless to if, no need for NA
        if (defined $count) {   
            $total += $count;
        }
    }
    # move print outside loop so it happens once instead of per-file
    print '\t$total\n'; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am curious if I can get some help with Open Graph since I
can someone explain the best way to get around the following, rather curious type
I'm curious if someone can point me in the right direction here. I'm learning
I am a little out of my depth here, I'll be honest. I am
I am just curious if someone can get me pointed in the right direction
Edit: I'm really just curious as to how I can get this regex to
I've always been curious: how can I perform arithmetic operations on very long decimals--for
I'm trying to setup a build file and I was curious if you can
I'm no expert in parallel programming. But I'm curious if I can use them
I'm currently using NVelocity to render some email templates. I'm curious how I can

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.