[comp.lang.perl] How to make a local

FFAAC09@cc1.kuleuven.ac.be (Paul Bijnens) (06/01/91)

I have a filehandle that is only used in a subroutine.  To avoid
stepping on some other global filehandle, how do I make this
filehandle local to this subroutine.  I cannot use local(), because
its elements must be legal lvalues.
I want to do something like this:

sub makeassoc {             # learn file freqtop by heart
    local(FH);              # this is illegal...???

    open(FH, "/usr/local/lib/freqtop") ||  die("Oops, freqtop: $!\n");
    while (<FH>) {
        chop;
        $top{$_}++;   # %top is a global array
    }
    close(FH);
}

An ugly workaround I use now:
    open(F1934547838, "...");
and hope to not use the same number twice by accident.

(Perl 4.0, pathlevel 3 if it matters)
--
Polleke   (Paul Bijnens)
Linguistics dept., K. University Leuven, Belgium
FFAAC09@cc1.kuleuven.ac.be

tchrist@convex.COM (Tom Christiansen) (06/01/91)

From the keyboard of FFAAC09@cc1.kuleuven.ac.be (Paul Bijnens):
:I have a filehandle that is only used in a subroutine.  To avoid
:stepping on some other global filehandle, how do I make this
:filehandle local to this subroutine.  I cannot use local(), because
:its elements must be legal lvalues.
:I want to do something like this:
:
:sub makeassoc {             # learn file freqtop by heart
:    local(FH);              # this is illegal...???

right.  you need 

    local(*FH)

this is question #23 in the FAQ, which I'll be updating a wee bit
and reposting some time this weekend. 

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time."