Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!bmc.uu.se!kuling!jand From: jand@kuling.UUCP (Jan Dj{rv) Newsgroups: comp.lang.perl Subject: How do I create new filehandles? (and an unrelated bug) Message-ID: <1593@kuling.UUCP> Date: 18 Jul 90 15:02:53 GMT Reply-To: jand@kuling.UUCP (Jan Dj{rv) Organization: Dept. of Computer Systems, Uppsala University, Sweden Lines: 48 I want to make a sub which opens a file and returns a filehandle. Here's my naive solution: sub new_file { local($file) = @_; open(F, "> $file") || die "Can't open $file\n"; return *F; } (The real application is a bit more involved...:-). However, this doesn't work, since perl uses the same fd for F in all calls to new_file. *FIRST = &new_file('file_one'); print fileno(FIRST), "\n"; *SECOND = &new_file('file_two'); print fileno(SECOND), "\n"; exit 0; gives prints 3 two times. What is the proper way to do this? And now for something completly different... With perl PL 18: % perl -e 'print time;' 648311529% % perl -e 'print time, "\n";' No comma allowed after filehandle at /tmp/perl-ea01682 line 1. % perl -e 'print "", time, "\n";' 648311550 % The same thing seems to happens for any print statement that has a builtin with no arguments as its first argument. Like in perl -e '$_ = 3.141;print cos, "\n";' perl -e 'print eof, "\n";' and so on. A bug surely? Jan D.