Question: I have an assignment that asks: Compose a Perl script shown below (dump-coords.pl in our files), which uses an array (@genes) to hold information for
I have an assignment that asks:
Compose a Perl script shown below ("dump-coords.pl" in our files), which uses an array (@genes) to hold information for two genes in the ../../bio425/data/mys.coord2 file. Each element of the array would be a reference to a hash. The hash reference itself would hold gene information in the following format: e.g., $gene={'id'=>'0001', 'start'=>16, 'end'=>324, 'frame'=>'+1', 'score'=>0.929}. Print the array by using the Dumper function.
Do not hard-code the values of the hash within the code only the keys (id, start, stop, frame, score), the script must parse the data for the values from the file! Tip: read elements of line into array, then construct anonymous hash (with $ not %) hashes using values from the elements of the array, and then push the anonymous hash to the @genes array. Remember you will need an intermediate array which will hold the information for the elements of each line, and will be "reloaded with each line. Use the following skeleton code :
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # print complex data structure # ---------------------------------------- # Author : WGQ # Date : February 30, 2015 # Description : Read coord file # Input : A coord file # Output : Coordinates and read frame for each gene # ---------------------------------------- my @genes; # declare the array while(<>) { # this means that as long as lines come from the pipe we keep going my $line = $_; # a line that come from the pipe (we go line by line) next unless $line =~ /^\d+/; # skip lines except those reporting genes } print Dumper(\@genes); exit; I don't even know how to approach this, this is my first time perl scripting and I am really confused. Any insight would be extremely helpful.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
