Re: First-Class Filehandle Trick in 5.8
From: Brian McCauley (nobull_at_mail.com)
Date: 01/30/04
- Next message: fulko.hew_at_sita.aero: "how to loop over instances of a class"
- Previous message: David K. Wall: "Re: regexp"
- Next in thread: Ilya Zakharevich: "Re: First-Class Filehandle Trick in 5.8"
- Reply: Ilya Zakharevich: "Re: First-Class Filehandle Trick in 5.8"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jan 2004 19:52:03 +0000
Scott McGerik <scottlm@visi.com> writes:
> I am using the First-Class Filehandle Trick, described at
> http://perl.plover.com/local.html#3_The_First_Class_Filehandle_Tr.
>
> In a particular program, I had this line:
>
> $INFILE = do { local *FH }; $OUTFILE = do { local *FH };
>
> I then proceed to open $INFILE for reading and $OUTFILE for writing with
>
> unless ( open $INFILE, '<', $infile ) {
>
> and
>
> unless ( open $OUTFILE, '>', $outfile ) {
>
>
> This worked in 5.6.1, but when I do the same under 5.8.0, I get the
> following error message:
>
> Filehandle FH opened only for output at ...
>
> I find this confusing because I thought that
>
> do { local *FH }
>
> would return an unnamed glob. But from the error message, it appears
> that it returned the glob for FH.
>
> I looked through the perldelta file, at
> http://www.perldoc.com/perl5.8.0/pod/perldelta.html, for 5.8, but I did
> not find any hints. Pointers and explanations are appreciated.
I must admit that my gut feeling is that the semantics of do { local
*FH } would not be something I'd expect to be stable.
Indeed anything to do with putting bare GLOBs in to scalars as opposed
to GLOBrefs makes my head (and my guts) spin.
I suggest you ask MJD what are the 'definite disadvantages' he
perceives in using GLOBrefs like everybody else does.
(Note that as of 5.6.1[*] you have autovification of GLOBrefs in open()
et al).
All that said, I just tried MJD's hack in 5.8.0 and it worked just
fine. So this brings us back to the advice is the posting guidelines:
"First make a short (less than 20-30 lines) and /complete/ program
that illustrates the problem you are having. People should be able to
run your program by copy/pasting the code from your article."
[*] The autovification functionality appears in 5.6.1 but didn't get
into the POD in that version.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
- Next message: fulko.hew_at_sita.aero: "how to loop over instances of a class"
- Previous message: David K. Wall: "Re: regexp"
- Next in thread: Ilya Zakharevich: "Re: First-Class Filehandle Trick in 5.8"
- Reply: Ilya Zakharevich: "Re: First-Class Filehandle Trick in 5.8"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|