--- Stephen Nelson <[EMAIL PROTECTED]> wrote:
> 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...

Another trick -- use FileHandle and put them into an array.

  my @FILE;
  for (1..5) {
     $FILE[$_] = new FileHandle "CHR$_" or die "CHR$_: $!";
  }

now you can say:

    print $FILE[$_] ">$k\t$all_genes{$k}\n";

 
> > -----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;
> >                  }
> >
> >
> 


=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=============================================================
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Reply via email to