David Romero wrote:
2008/6/25 Eng. Fadhl Al_Akwaa <[EMAIL PROTECTED]>:
I could not do it with matlab could perl do it?
I appreciate if I have solution for this problem
I try to extract two columns from a text file(8 columns) with variable
number of headerlines, and variable line length.
below is one line of my data
S= 'GO:0000022 0.00312066574202497 9/2884 1/597 0.0023457 NA mitotic
spindle elongation YBL084C '
How could I get column 4 , 5 using perl.
This is one way
open (FILE,"file.txt") or die "can't open file";
open (DESTINATION,'newfile.txt') or die "can't open file";
You should include the $! variable in the error message so you know
*why* open failed. You are opening 'newfile.txt' for *input* but you
are trying to print to its filehandle, you need to open it for output.
open FILE, '<', 'file.txt' or die "can't open 'file.txt' $!";
open DESTINATION, '>', 'newfile.txt' or die "can't open 'newfile.txt' $!";
while(<FILE>){
my ($col1, $col2, $col3, $col4, $col5) = split(/[\s\t]/,$_);
[\s\t] could be simplified to \s because the \s character class includes
the \t character, but it is better if you match one or more as \s+ or
why not just:
my ($col1, $col2, $col3, $col4, $col5) = split;
print DESTINATION "$col4 $col5";
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/