Answers.Body: <p>The following Perl documentation pages should be informative:</p>
  
  <ul>
  <li><a href="http://perldoc.perl.org/functions/split.html" rel="nofollow noreferrer">split</a> - for splitting a scalar at all matches of a defined pattern</li>
  <li><a href="http://perldoc.perl.org/perlreftut.html" rel="nofollow noreferrer">perlreftut</a> - discusses the approach of anonymous variables and how to combine them</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T05:52:13.277Z
Answers.LastActivityDate: 2018-03-14T05:52:13.277Z
Answers.UserDisplayName: gringer
Answers.Body: <p>Perhaps this small test script will help demonstrate some of the principles:</p>
  
  <pre><code>#!/usr/bin/env perl                                                                                                                                              
  
  use strict;
  use warnings;
  use Data::Dumper;
  
  my @arr;
  
  # define the current line    
  my $line = "foo\tbar\tbaz\n";
  
  # remove the trailing newline character
  chomp $line; 
  
  # put the line's elements into an anonymous array
  my ($a, $b, $c) = split('\t', $line);
  
  # insert key-value pairs into anonymous hash    
  my $hash = {a =&gt; $a, b =&gt; $b, c =&gt; $c};
  
  # add the hash table to the array
  push @arr, $hash;
  
  # print the array
  print Dumper \@arr;
  </code></pre>
  
  <p>Run this script and see what it prints out.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T09:16:18.650Z
Answers.Text: `my ($id, $start, $end, $frame, $score) = split('  ', $line);
     
      my $hash = {id => $id, start => (at) start, end => (at)end, frame => (at) frame, score => (at) score};`
Answers.UserDisplayName: code_pink
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T09:17:41.913Z
Answers.Text: is this sort of in the right direction
Answers.UserDisplayName: code_pink
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T09:23:13.070Z
Answers.Text: `my ($id, $start, $end, $frame, $score) = split('\t', $line); my $hash = (id => $id, start => $start, end => $end, frame => $frame, score = $score);`
Answers.UserDisplayName: Alex Reynolds
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T18:46:25.787Z
Answers.Text: Sorry, that should be: `my $hash = { ... }` not using parentheses, but brackets. I can't edit my previous comment so hopefully this helps.
Answers.UserDisplayName: Alex Reynolds
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T06:31:33.300Z
Answers.LastActivityDate: 2018-03-14T06:48:49.310Z
Answers.LastEditDate: 2018-03-14T06:48:49.310Z
Answers.UserDisplayName: Alex Reynolds
Body: <p>Basically I have a perl script in which I have an array (where each element of the array references a hash) and need to be able to print the array with a dumper function. 
  Thus I need to be able to split the $line on white spaces and save into variables and then construct anonymous hash and push into @genes:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use Data::Dumper; # print complex data structure
  my @genes; # declare the array
  while(&lt;&gt;) { # 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 
    &lt;split the $line on white spaces and save into variables&gt;
    &lt;anonymous hash and push into @genes&gt;
  }
  print Dumper(\@genes);
  exit;
  </code></pre>
  
  <p>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.</p>
  
  <p>So far I have:</p>
  
  <pre><code>my $gene = {'id' =&gt; $id, 'start' =&gt; $start, 'end' =&gt; $end, 'frame' = $frame, 'score' =&gt; $score};
  my @line_split = split(' ', $line);
  my $id = $line_split [0], $start = $line_split [1], $end = $line_split [2], $frame = $line_split [3], $score = $line_split [4]
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-14T06:19:39.543Z
Comments.Text: What is the format of `mys.coord2`?
Comments.UserDisplayName: Alex Reynolds
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-14T08:25:12.803Z
Comments.Text: 00001      16     324  +1   0.929
  00002     751     308  -2   0.911
Comments.UserDisplayName: code_pink
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-14T08:25:45.317Z
Comments.Text: simply just contains two lines
Comments.UserDisplayName: code_pink
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-15T16:30:38.557Z
Comments.Text: Hi code_pink now the question is more specific, but we still don't know how is it failing, or why. Could you [edit] it further to include this information? Also if you would like to have some guidance explaining your reasoning with your code would be useful to explain why it is a good direction or not (this is a great tool to find the way to code). Also if you mark one answer as accepted, people (usually) won't answer further.
Comments.UserDisplayName: llrs
Tags: <gene><perl><homework>
Title: Writing a perl script to holding information for two genes
ThreadText: # Writing a perl script to holding information for two genes
  
  (Asked by: username_0 on 2018-03-14)
  
  Basically I have a perl script in which I have an array (where each element of the array references a hash) and need to be able to print the array with a dumper function.
  Thus I need to be able to split the $line on white spaces and save into variables and then construct anonymous hash and push into @genes:
  
  ```
  #!/usr/bin/perl
  use strict;
  use warnings;
  use Data::Dumper; # print complex data structure
  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 
    <split the $line on white spaces and save into variables>
    <anonymous hash and push into @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.
  
  So far I have:
  
  ```
  my $gene = {'id' => $id, 'start' => $start, 'end' => $end, 'frame' = $frame, 'score' => $score};
  my @line_split = split(' ', $line);
  my $id = $line_split [0], $start = $line_split [1], $end = $line_split [2], $frame = $line_split [3], $score = $line_split [4]
  
  ```
  
  **Tags:** gene, perl, homework
  
  > **Comments:**
  > **username_1**: What is the format of `mys.coord2`?  
  > **username_0**: 00001      16     324  +1   0.929 00002     751     308  -2   0.911  
  > **username_0**: simply just contains two lines  
  > **username_2**: Hi username_0 now the question is more specific, but we still don't know how is it failing, or why. Could you [edit] it further to include this information? Also if you would like to have some guidance explaining your reasoning with your code would be useful to explain why it is a good direction or not (this is a great tool to find the way to code). Also if you mark one answer as accepted, people (usually) won't answer further.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-03-14. Score: 6 | Accepted answer
  
  Perhaps this small test script will help demonstrate some of the principles:
  
  ```
  #!/usr/bin/env perl                                                                                                                                              
  
  use strict;
  use warnings;
  use Data::Dumper;
  
  my @arr;
  
  # define the current line    
  my $line = "foo\tbar\tbaz\n";
  
  # remove the trailing newline character
  chomp $line; 
  
  # put the line's elements into an anonymous array
  my ($a, $b, $c) = split('\t', $line);
  
  # insert key-value pairs into anonymous hash    
  my $hash = {a => $a, b => $b, c => $c};
  
  # add the hash table to the array
  push @arr, $hash;
  
  # print the array
  print Dumper \@arr;
  
  ```
  
  Run this script and see what it prints out.
  
  > **Comments:**
  > **username_0**: `my ($id, $start, $end, $frame, $score) = split('  ', $line);         my $hash = {id => $id, start => (at) start, end => (at)end, frame => (at) frame, score => (at) score};`  
  > **username_0**: is this sort of in the right direction  
  > **username_1**: `my ($id, $start, $end, $frame, $score) = split('\t', $line); my $hash = (id => $id, start => $start, end => $end, frame => $frame, score = $score);`  
  > **username_1**: Sorry, that should be: `my $hash = { ... }` not using parentheses, but brackets. I can't edit my previous comment so hopefully this helps.  
  
  ---
  
  ### Answer by username_3 on 2018-03-14. Score: 2
  
  The following Perl documentation pages should be informative:
  
  * [split](http://perldoc.perl.org/functions/split.html) - for splitting a scalar at all matches of a defined pattern
  * [perlreftut](http://perldoc.perl.org/perlreftut.html) - discusses the approach of anonymous variables and how to combine them
  
  
  ---
  
  