Fortunately or unfortunately, you can't print to files just by using $file
as a filehandle. You need to open the file first.

<CODE>
 foreach $k (sort keys (%all_genes)) {
          for (1..5){
                  if ($k =~ /[$_]g/){
                          $file = "CHR$_";
                          open(FILE, "> $file") or die "Couldn't open
'$file': $!; stopped";
                          print FILE ">$k\t$all_genes{$k}\n";
                          print ">$k \t $all_genes{$k}\n";
                          close(FILE);
                          last;
                  }
</CODE>

That's if you want your files to be CHR1, CHR2, etc...

> -----Original Message-----
> From: Hans Holtan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 27, 2001 4:36 PM
> To: [EMAIL PROTECTED]
> Subject: using strict
>
>
> Hi everyone,
>
> I get this error when I run my script, and I don't understand why:
>
> "Can't use string ("CHR3") as a symbol ref while "strict refs" in use
> at AtIntergenicTableSort.pl line 53. "
>
> I'm trying to split my output into 5 seperate files based on what is
> in the key. Here is a snip of  code:
>
> #Sort the hash and write to a new file
> foreach $k (sort keys (%all_genes)) {
>          for (1..5){
>                  if ($k =~ /[$_]g/){
>                          $file = "CHR$_";
>                          print $file ">$k\t$all_genes{$k}\n";
>                          print ">$k \t $all_genes{$k}\n";
>                          last;
>                  }
>
>

Reply via email to