Shahzad A Khalid wrote:
> 
> Hi,

Hello,

> I have a similar problem that someone just asked about reading specific
> columns from a file and writing to another file. Eventually, I want to
> read the written file to be loaded into Matlab. Im having trouble writing
> the regular expression for this file. The format of the file looks like this:
> 
> Cell1=481 13 N control AFFX-MurIL2_at 0 13 A A A 0  8801  -1  -1  99
> Cell2=481 12 N control AFFX-MurIL2_at 0 13 A T A 0  8161  -1  -1  99
> 
>  I want to read the column mentioning 481 and leaving Cell?= portion.
> Then second col. ie 13/12, third col, 5th(AFFX-KurIL2_at) and 7th(13/13).
> Please suggest how do i do that. The code i tried is as follows:
> 
> $writefilename = 'final.txt';
> open(READFILE1,$writefilename);
> open(WRITEFILE1,">>cdf.txt");

You should _ALWAYS_ verify that your files were opened correctly:

open( READFILE1, $writefilename ) or die "Cannot open $writefilename:
$!";
open( WRITEFILE1, ">>cdf.txt" ) or die "Cannot open cdf.txt: $!";


> @array=<READFILE1>;
> $len=scalar(@array);
> print $len;
> #foreach $lineblock(@array){
>  #  
> @colarray=split(/\w+\=\d+\s+\d+\s+\w\s+\w+\s+\w+\-\w+\-\w+\s+\d\s+\d+\s+\w\s+\w\s+\w\s+\d\s+\d+\s+\d\s+\d\s+\d+/,
>  $lineblock);
>  #  print WRITEFILE1 @colarray[1];
> 
> #}
> foreach$lineblock(@array){
>         @colarray=split(/\s*/,$lineblock);

You are telling split() to split on zero or more whitespace which is the
same as splitting the string into individual characters and removing the
whitespace.

$ perl -le'print ">$_<" for split /\s*/, "one  two"'
>o<
>n<
>e<
>t<
>w<
>o<


>         $colarray[0]=~ s/Cell\d=//ig;
>         foreach $col(@colarray){
>         print WRITEFILE1 $col;
>         }
> }

According to your code, this should do the same thing:

for ( @array ) {
    s/Cell\d=//i;
    s/\s+//g;
    print WRITEFILE1;
    }


> close READFILE1;
> close WRITEFILE1;
> exit;


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to