Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!elroy!devvax!lwall From: lwall@devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.d Subject: Re: perl filehandle question Message-ID: <2389@devvax.JPL.NASA.GOV> Date: 6 Jul 88 03:06:46 GMT References: <336@rhesus.primate.wisc.edu> Reply-To: lwall@devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 36 In article <336@rhesus.primate.wisc.edu> bin@rhesus.primate.wisc.edu (Brain in Neutral) writes: : : If I have a perl subroutine such as : : sub x : { : local ($fileh); # file handle : : ... : } : : how do I reference the file handle? E.g., should I say : : open ($fileh, "/tmp/junk"); : or : open (fileh, "/tmp/junk"); : : I presume the latter from the documentation, but it seems inconsistent : to have to declare it with the dollar sign and use it without... $fileh can never be a filehandle. It CAN be a variable pointing to a filehandle, however. open ($fileh, "/tmp/junk"); and open (fileh, "/tmp/junk"); are equivalent if and only if $fileh eq 'fileh'. Anywhere you can use a filehandle (without the $) you can use an indirect filehandle (by substituting the name of any variable (with a $) that contains the name of that filehandle). If you're going to use $fileh to hold your filehandle, just use $fileh everywhere and make sure $fileh is initialized to the filehandle you want. Larry Wall lwall@jpl-devvax.jpl.nasa.gov