in reply to spliting a table into individual columns

Welcome to the Monastary!

Your (incorrect) code should look like this, when posted to this site. This is produced using "code" tags:

use warnings; use strict; sub read_TABLE{ my($file_name)=@_; open (OPEN_TABLE,$file_name); if(open (OPEN_TABLE, $file_name)){ print "Can open file \"$file_name\" \n"; } unless(open(OPEN_TABLE, $file_name)){ print STDERR "Can't open file \"$file_name\" + \n"; } my@table; while(my$line=<OPEN_TABLE>){ chomp $line; my @data=split(/\t/,$line,5); push @table,\@data; } close OPEN_TABLE; return @table; } my @s=read_table("TABLE.txt"); foreach my $line(@s) { my$start=[0]; my$end=[1]; my$name=[2]; my$strand=[3]; my$type=[4]; print "$type\n"; }

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

Replies are listed 'Best First'.
Re^2: spliting a table into individual columns
by Anonymous Monk on Dec 21, 2007 at 02:12 UTC
    Your code makes THREE attempts at opening the file. The first attempt probably succeeds, but your code does not bother to verify that. The second attempt probably fails, giving you the error message. Please see the sample code for the "open" function.

    If the first attempt succeeds then the second attempt will close the filehandle before it opens the filehandle again and then the same will happen for third attempt.

    if the first attempt fails then the second and third attempts will also fail.