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

  • SEARCH
  • Home
  • 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 9137983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:11:51+00:00 2026-06-17T09:11:51+00:00

I have a program that creates an array of hashes while parsing a FASTA

  • 0

I have a program that creates an array of hashes while parsing a FASTA file. Here is my code

use strict;
use warnings;

my $docName = "A_gen.txt";
my $alleleCount = 0;
my $flag = 1;

my $tempSequence;
my @tempHeader;
my @arrayOfHashes = ();

my $fastaDoc = open(my $FH, '<', $docName);
my @fileArray = <$FH>;

for (my $i = 0; $i <= $#fileArray; $i++) {
    if ($fileArray[$i] =~ m/>/) { # creates a header for the hashes
    $flag = 0;
    $fileArray[$i] =~ s/>//;
    $alleleCount++;
    @tempHeader = split / /, $fileArray[$i];
    pop(@tempHeader); # removes the pointless bp
    for (my $j = 0; $j <= scalar(@tempHeader)-1; $j++) {
        print $tempHeader[$j];
        if ($j < scalar(@tempHeader)-1) {
            print " : "};
            if ($j == scalar(@tempHeader) - 1) {
                print "\n";
            };
        }
    }
    # push(@arrayOfHashes, "$i");

    if ($fileArray[$i++] =~ m/>/) { # goes to next line
        push(@arrayOfHashes, {
            id => $tempHeader[0],
            hla => $tempHeader[1], 
            bpCount => $tempHeader[2],
            sequence => $tempSequence
        });
        print $arrayOfHashes[0]{id};
        @tempHeader = ();
        $tempSequence = "";
    }
    $i--; # puts i back to the current line

    if ($flag == 1) {
        $tempSequence = $tempSequence.$fileArray[$i];
    }
}

print $arrayOfHashes[0]{id};
print "\n";

print $alleleCount."\n";
print $#fileArray +1;

My problem is when the line

print $arrayOfHashes[0]{id};

is called, I get an error that says

Use of uninitialized value in print at fasta_tie.pl line 47, line 6670.

You will see in the above code I commented out a line that says

push(@arrayOfHashes, “$i”);

because I wanted to make sure that the hash works. Also the data prints correctly in the
desired formatting. Which looks like this

HLA:HLA00127 : A*74:01 : 2918

  • 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-17T09:11:52+00:00Added an answer on June 17, 2026 at 9:11 am

    try to add

    print "Array length:" . scalar(@arrayOfHashes) . "\n"; 
    

    before

    print $arrayOfHashes[0]{id};
    

    So you can see, if you got some content in your variable. You can also use the module Data::Dumper to see the content.

    use Data::Dumper;
    print Dumper(\@arrayOfHashes);
    

    Note the ‘\’ before the array!

    Output would be something like:

    $VAR1 = [
    {
    ‘sequence’ => ‘tempSequence’,
    ‘hla’ => ‘hla’,
    ‘bpCount’ => ‘bpCount’,
    ‘id’ => ‘id’
    }
    ];

    But if there’s a Module for Fasta, try to use this. You don’t have to reinvent the wheel each time 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that creates a small file in the Bin directory for
I have a program that creates semaphore. But when i try to use SETALL,
I'm experimenting with file I/O. I have a small practice program that creates a
I have a program that creates multiple text files of rdf triples. I need
I have a program that creates a JFrame and makes it visible. Is there
Greetings I have a program that creates multiples instances of a class, runs the
I have a simple program that creates a thread, loops twenty times and then
I have a Delphi program that creates HTML files. Later when a button is
I have a program that starts up and creates an in-memory data model and
I have made a program that scans rss feeds. This same program creates feeds

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.