Newsgroups: comp.lang.perl
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sid
From: sid@think.com (Sid Stuart)
Subject: Associative arrays as indirect filehandles?
Message-ID: <1991Jun11.230027.17017@Think.COM>
Originator: sid@grub.think.com
Sender: news@Think.COM
Organization: Thinking Machines Corporation, Cambridge MA, USA
Distribution: na
Date: Tue, 11 Jun 91 23:00:27 GMT
Lines: 34

I have a program in which I would like to split a file
up into smaller files, based on the data in the main file.
For example, if a line has the word moop in it, I would
like to put it in the file moop. To do this I would like
to use an associative array as indirect filehandles. Perl
kind of wants to let me do this, but not all the way.
(Reminds me of my first girl friend.) A call to the open
command will pass the syntax checker when using an associative
array, but a call to print fails with a syntax error.

I have a simple test program as an example:

  #!/usr/local/bin/perl

  open($froob{'myfroob'}, ">/tmp/testfile");
  print ($froob{'myfroob'} "Froob\n");


It fails under Perl 3.0, patch level 41 with the following
error message:

  grub.think.com {81} tester
  syntax error in file tester at line 4, next 2 tokens "} "Froob\n""
  Execution of tester aborted due to compilation errors.


Am I missing something or will this just not work?


-- 
Sid Stuart, Thinking Machines Corp.

sid@think.com
{uunet,harvard}!think!sid
