How do I change the scope of a filehandle? 
Author Message
 How do I change the scope of a filehandle?

I'm trying to use the "use strict 'vars'" feature of Perl 5 to get
strict lexical scoping.  However, I can't figure out how to construct
a "my" statement for a filehandle.  I've tried
        my *HANDLE;
        my \*HANDLE;
        my HANDLE;
        my \HANDLE;
all without success.  The first two generate the message:

Global symbol "HANDLE" requires explicit package name at testfh.pl line 8.

and the latter two generate:

Can't declare constant item in my at testfh.pl line 8, near "HANDLE;"
Global symbol "HANDLE" requires explicit package name at testfh.pl line 9.

Here is the code fragment:

#!/usr/local/bin/perl

use strict 'vars';

test_sub();

sub test_sub {
    my *HANDLE;
    open(HANDLE, ">/tmp/$$");
    close(HANDLE);

Quote:
}

I am running under perl 5.000 and SunOS 4.1.3_U1.  I've looked through
the Perl FAQ and Perl manpages, and haven't been able to figure out
how to do this...


Mon, 24 Nov 1997 03:00:00 GMT  
 How do I change the scope of a filehandle?

Quote:
>I'm trying to use the "use strict 'vars'" feature of Perl 5 to get
>strict lexical scoping.  However, I can't figure out how to construct
>a "my" statement for a filehandle.

It's not possible.

In perl5.000, you have to qualify your file handles all the time, e.g
write ::HANDLE.  That's a nuisance.  In perl5.001, "strict 'vars'" no
longer checks file handles.

If Larry had realized 9 years ago what Perl would eventually develop
into, he would have picked a type marker for file handles, maybe "?",
and we'd have to write things like "open(?HANDLE, 'file');" and that
would have allowed us to write "my ?handle;".

Alas, that's not what happened and now it's too late for such a drastic
change to the language.

--
Sorry,

HansM



Sun, 30 Nov 1997 03:00:00 GMT  
 How do I change the scope of a filehandle?
: into, he would have picked a type marker for file handles, maybe "?",
: and we'd have to write things like "open(?HANDLE, 'file');" and that
: would have allowed us to write "my ?handle;".

(Mnemonic: ? looks like a handle :)

--
   __ __ _   _   .__   __ _   . __ _   __  
  /_ /_ /_) /_) / /   /_ /_) / /_ /_) /_ /   Beim Schlump 52
 /_//_ / | / | / /   /_// | / /_ /_) /_ /_   20144 Hamburg,Germany



Fri, 05 Dec 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. filehandle declaration and static scope in perl5

2. Changing FORMAT filehandles -

3. Changes in tied filehandles in 5.005?

4. ref doesn't return FileHandle for FileHandles?

5. print to filehandle when filehandle is a $var

6. ANNOUNCE: FileHandle::Rollback - FileHandle with rollback and commit

7. Redirecting filehandle to multiple filehandles

8. Benchmark: local filehandle vs. Filehandle.pm

9. global filehandle, dereferencing filehandle

10. Changing One Array Changes Unrelated Arrays -- Why?

11. change background color on a widget when the textvariable changes

 

 
Powered by phpBB® Forum Software