From: drieux <[EMAIL PROTECTED]> > On Wednesday, June 5, 2002, at 03:05 , Jenda Krynicky wrote: > > > From:"siren jones" <[EMAIL PROTECTED]> > >> I'm trying to figure out some cgi code which has the statment > >> > >> &readparse(*input); > [..] > > What is it? A clear hint that the code was written for Perl 4. > > Run away from it if you can. > > > > Jenda > > > > P.S.: The *input is a glob. Most probably "containing" a filehandle > > in this case. > > > granted the code referenced in: > > Found in /System/Library/Perl/pods/perlfaq7.pod > How can I pass/return a {Function, FileHandle, Array, > Hash, Method, Regex}? > > that comes with the default perl 5.6.0 > > recommends that one check the pass by reference in perlsub > and the typeglob section of perldoc perldata > > where we notice: > > " Temporary Values via local() > > WARNING: In general, you should be using `my' instead of > `local', because it's faster and safer. Exceptions to > this include the global punctuation variables, filehandles " > > but provides the same 'splutter(\*STDOUT)' type of > passing a typeglob around... > > all of which leads me back to the question of whether your > position here is advocating something on the order of > > open(FH, $filename) or die "no open $filename:$!\n"; > > my $fh = fileno(FH); > > goSubBeatState($fh, @mess_to_grovel); > > > or should we have gone through IO::Handle to begin with???? > > or is the problem here that passing file handles around is not > always a really smart thing to do to begin with???? > > I know that I have code where I pass around the FD for a socket.... > > so catch me up here homeboy - what is the orthodox trick?
The problem with filehandles is that until fairly late the only reasonable way to pass a filehandle was using the typeglobs. It is not particularly nice, but it's widely used The currently prefered way (IMHO) is to use either FileHandle or IO::Handle and have the filehandles as normal lexical scalars that you can pass around anyway you like. The problem is that a lot of people are either used to passing filehandles via typeglobs or dislike to have to include another module into their script. I find use FileHandle; ... sub foo { my $FH; open $FH, '<'.$filename or die ... bar( $FH, 'some', 'params'); ... much cleaner than sub foo { local *FH; open FH, '<'.$filename or die ... bar( *FH, 'some', 'params'); ... But as lots of other things it's just a matter of personal taste. Jenda P.S.: It's not just the *input why I said it was a Perl4 code. It was also the & and besides the readparse() is part of the old cgi-lib.pl library. =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]