Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!rutgers!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Local file handles? Keywords: FILEHANDLE LOCAL Message-ID: <10303@jpl-devvax.JPL.NASA.GOV> Date: 9 Nov 90 01:40:38 GMT References: <9317@netxcom.DHL.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 40 In article <9317@netxcom.DHL.COM> elw@netex.netx.com (Edwin Wiles) writes: : Is there any way to declare a file handle to be local to a given subroutine? There are two ways. First, using an indirect filehandle: $nextfh = 'fh000'; sub Arecursive { local($somefile, @somejunk) = @_; local($INPUT) = $nextfh++; # magical increment open($INPUT, "< somefile" ); while( <$INPUT> ) { ... @Bvalue = Arecursive( $_, @morejunk ); ... } close( $INPUT ); return @Avalue; } or, using a * type glob: sub Arecursive { local($somefile, @somejunk) = @_; local(*INPUT); open(INPUT, "< somefile" ); while( ) { ... @Bvalue = Arecursive( $_, @morejunk ); ... } close( INPUT ); return @Avalue; } Larry