in reply to spliting a table into individual columns

I don't know what your input data file looks like (presumably it's plain text containing 5 tab-delimited values per line), but your code could be simplified to the following, in order to do what I think you want:
#!/usr/bin/perl use warnings; use strict; sub read_TABLE { my ( $filename ) = @_; open( TBL, $filename ) or die "cannot open $filename: $!\n"; my @table; while ( <TBL> ) { chomp; push @table, [ split( /\t/, $_ , 5 ) ]; } close TBL; return @table; } for my $row ( read_table( "TABLE.txt" )) { my ( $start, $end, $name, $strand, $type ) = @$row; print "$type\n"; }
Some notes:

Replies are listed 'Best First'.
Re^2: spliting a table into individual columns
by C_elegance (Initiate) on Dec 21, 2007 at 11:43 UTC
    firstly I'm sorry for not formatting my message properly, i didn't think anyone would bother with me (i've tried other fora!). i decided to try this life line with the last ounces of my sanity just before collapsing to sleep. I WON'T DO IT AGAIN. i'll try the advice and will be back with the next problem
Re^2: spliting a table into individual columns
by C_elegance (Initiate) on Dec 21, 2007 at 12:49 UTC
    when i put your suggestion into the action i get: "Use of uninitialized value in concatenation (.) or string at 8.pl line 22" repeating itself. o'k now i'm back to write the proper answer to your first mail.
Re^2: spliting a table into individual columns
by C_elegance (Initiate) on Dec 21, 2007 at 13:29 UTC
    what I'm trying to do - it's to extract the data from the file that is not a table but arranged in 8 columns separated by space (which i can separate [split(' ',$_, 8)] the next step is to search "the type" array for certain information, select only those. from there- using id (different column) and the coordinates also different column, to fish that part of the data from another file containing many id with their data- including the ones i need so i want to find the type, select for this. then i have to select for other parameters in other columns in the same way, then match the id to the coordinates - hash (of start -end joined into one information by join subroutine, that will return the parameters as regular expression that can be matched)? search the other file for the same ids, select only those and then fish out the part of the data i need and select it before i go any further....

      As you are a beginner, I just wanted to point you to a valuable tool bundled right into perl, Data::Dumper. My pointing this out won't necessarily _solve_ your problem, but it will go a long way towards helping you _visualize_ it.

      All you need to do is put use Data::Dumper; in your script. Then you'll be able to use it to display the contents of your variables with a line like:

      print Dumper( $foo );

      So, you might use it in your script to display your @s array, or within your foreach loop to show the current value of your $line variable.

      Keep Data::Dumper in mind. It's helped me learn all sorts of things in perl because it makes it so easy to actually see what's happening in a script.

      --
      naChoZ

      Therapy is expensive. Popping bubble wrap is cheap. You choose.

      i get: "Use of uninitialized value in concatenation (.) or string at 8.pl line 22"

      ... the file ... is not a table but arranged in 8 columns separated by space...

      So, if you used the code as I posted it on the file that you describe, then yes, you would get that message about line 22 (the "print" statement) and no other output, because the split was based on /\t/ (as you had it in your original post), and with no tabs in the file, nothing would be assigned to $type. I gather you've gotten past that problem, and are moving on to the real job.

      But the rest of your description of the job is hard to follow. If you are having trouble working it out, you'll need to show us some sample data that will make it clear what you are trying to do. If you are using two or more input files, and trying to relate information across the files to get specific outputs, show us a few relevant lines from each input, and what the corresponding output should look like. Then show us the code you've tried so far.

      (Now that you've gotten past the issue of "splitting a table into individual columns", you might want this new information and question, about joining data from different inputs, to be the start of a new thread.)

        Thank you again for bothering with me, i don't know anyone, who knows Perl and i have an assignment to do. i don't know what are the rules of what's acceptable with asking questions on the fora... but I'm getting stuck on small things and can't move forward with bigger ones. I've managed to move pass this problem, but not much further than that.. as i was trying to organise other bits of my assignment. therefore i have a question, when you were a beginner, how did you cope, saved/organised your files? i've just realised that i have tones of files to go through at different stags of development and what worst, i've actually lost some bits, that were working... i find it so demoralising and would appreciate any helpful tips. thanks for now - will be back when next problem arises ... i.e. 5 min :)
        testing