Path: utzoo!attcan!uunet!fed!m1rcd00 From: m1rcd00@fed.FRB.GOV (Bob Drzyzgula) Newsgroups: comp.lang.perl Subject: Data-selected output channels Message-ID: <547@arccs1.fed.FRB.GOV> Date: 2 Mar 90 14:58:21 GMT Sender: news@fed.FRB.GOV Reply-To: rcd@fed.frb.gov Followup-To: comp.lang.perl Distribution: na Organization: Federal Reserve Board, Wash, DC Lines: 53 I would like to be able to direct my perl program output to one of several *simultaneously open* files, depending on input data. I had thought that perl's filehandle indirection capability would do this for me, but I guess not. The result of the script #!/usr/bin/perl foreach $i ("file1", "file2", "file3") { $openstring = ">$i"; open openstring; print openstring "$openstring\n"; } foreach $i ("file1", "file2", "file3") { $openstring = "$i"; print openstring "$openstring\n"; } is three files with the contents: "file1": >file1 "file2": >file2 "file3": >file3 file1 file2 file3 So apparantly an indirect filehandle is associated with *the most recently opened file* that went by that name. Setting $openstring = ">$i" in the second loop changes only file3 by putting a ">" at the beginning of the second through fourth lines, and using a different variable name in place of "openstring" in the second loop results in nothing being written as a result of the second loop, as does changing the last print statement to "print $openstring ...". Hence there appears to be no variable look-up done on the filehandle during the print statment, only during the open statement. Is there any way to do what I want, short of doing an open every time I want to write a record? Given my application, that's about 570,000 opens. The Solbourne is pretty fast, but... :-) -- Bob Drzyzgula rcd@fed.frb.gov, uunet!fed!rcd Federal Reserve Board, Washington, DC 20551