title: Read array data from a CSV or a config file instead of __DATA__ inside Perl script
body: <p>I'm a novice in Perl and recently came through a perl script which reads array data from <code>__DATA__;</code> (a inline data statement inside the perl script at the bottom) using <code>@flatfiledata = &lt;DATA&gt;;</code></p>
  <p>data looks as below inside the script at the bottom:</p>
  <pre><code>__DATA__;
  Arrays
  @cab_method::Concentration::Dilution
  @cab04_cartypes::XXXX Dye::Gag XXXXXX::LuciXXXX::Firefly LuciXXXX::Renilla LucifXXXX
  
  __END__;
  </code></pre>
  <p>I would like to keep this data inside a config file either csv or a tab delimited file
  and then read this data into array.</p>
  <p>below is the current subroutine which read this data from <code>__DATA__</code> statement at the bottom.</p>
  <pre><code># read data from __DATA__ section at end of program and put data into @flatfiledata array
  @flatfiledata = &lt;DATA&gt;;
  &amp;ReadArraysAndHashes;
  
  sub ReadArraysAndHashes {
      foreach $line (@flatfiledata) {
          chomp $line;
  
          # ok, some weird newline chars have ended up in data section, so...
          $line =~ s/\r|\n//g;
  
          # skip any lines that do not contain at least one '::'
          # (probably blank lines or comments)
  
          unless ( $line =~ /::/ ) { next }
  
          #split all the elements in the line into an array
          my @elements = split( /::/, $line );
  
          # The first element is the key;
          my $key = shift(@elements);
  
          # if the key starts with a '@,' you have an array;
          # if it starts with a '%,' it is a hash
          # either way, delete the symbol from the key
  
          $key =~ s/^(.)//;
          my $array_or_hash = $1;
  
          # create a hash of hashes
          if ( $array_or_hash eq '@' ) {
              $clrdata{array}{$key} = \@elements;
              @{$key} = @{ $clrdata{array}{$key} };
          }
          elsif ( $array_or_hash eq '%' ) {
              if ( $#elements % 2 != 1 ) {
                  print &quot;odd number of elements for $key\n&quot;;
              }
              my %hash = @elements;
              $clrdata{hash}{$key} = \%hash;
          }
      }
  }
  
  
  __DATA__;
  Arrays
  @cab_method::Concentration::Dilution
  @cab04_cartypes::XXXX Dye::Gag XXXXXX::LuciXXXX::Firefly LuciXXXX::Renilla LucifXXXX
  
  __END__;
  
  </code></pre>