in reply to Read in a file containing the criteria for a program when it runs

You may want to use array of arrays (AoA) to parse and store this file. For example,
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @filter; <>; # read one line from the file/stdin while (<>) { # read other lines chomp; # remove "\n" from the end of the line push @filter,[(split /\t/,$_)]; # create an array of the line by spli +tting it by <TAB>, make a reference of it and push the reference to t +he @filter array } @filter = sort { $a->[4] <=> $b->[4] } @filter; # sort the array by 5t +h element of embedded arrays print Dumper \@filter;
(EDIT: add chomp)
Sorry if my advice was wrong.
  • Comment on Re: Read in a file containing the criteria for a program when it runs
  • Download Code

Replies are listed 'Best First'.
Re^2: Read in a file containing the criteria for a program when it runs
by dkhalfe (Acolyte) on Jul 18, 2012 at 18:37 UTC

    This method is also great. I know that I can print any specific clump of data. Ex.  print Dumper \@filter[0] to get the first clump of data in the array. My question is, can I (and if I can, how can I) pull out the individual elements in the array. Ex.

    $VAR1 = \[ '1000_Genomes', '<=', '0.03', 'filter ', ' '1 ];
    is the output I get when I print  Dumper \@filter[0] . I need to be able to use each individual element (1000_Genomes, <=, 0.03, etc..) separately throughout my program. Should I store these values in variables or what? Thanks for your assistance!!!!

      You can access elements by their nubmers. For example, print $filter[0]->[0],"\n" should print 1000_Genomes.

      -> is necessary because @filter array contents are not real arrays, but references to arrays.

      Sorry if my advice was wrong.

        Would it be safe to use references to arrays in a program that will eventually sort through a TON of data? Also, through using references to array, I should be able to call on the individual elements when running my code, correct? Thank you so much. You have really helped me out!