Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Think about Loose Coupling
 
PerlMonks  

Re: Bareword "FILE" not allowed while "strict subs"

by shenme (Priest)
on Oct 08, 2004 at 21:47 UTC ( #397787=note: print w/ replies, xml ) Need Help??


in reply to Bareword "FILE" not allowed while "strict subs"

Any idea why this is happening?
Amazing, no one answered the question.

In the documentation you referenced they used FILEHANDLE to mean "generic file handle". In your code you did understand correctly that FILE was your file handle . . . but how to let Perl know that?

The Perl functions like open and close expect to get a file handle as the first argument. So they automatically convert the use of a bare 'FILE' to be the use of the file handle value associated with that name. Not quite magic, but just the obvious meaning.

But when you used 'FILE' with just any old subroutine name, like restore_parameters() from the CGI.pm module, Perl didn't know what to make of it. You could have 'meant' the scalar value, the array, the hash, ... or any of the things that might have been associated with that bare name. (Think of $FILE, @FILE, %FILE, etc.)

The use of *FILE (a 'typeglob') as ikegami suggested more or less says give the whole smash to the subroutine so that it can figure out which value/meaning to use.

The use of file handle values in specific variables as BUU and bpphillips demonstrated is the most explicit way for everyone to know what is meant, for _all_ uses.


Comment on Re: Bareword "FILE" not allowed while "strict subs"
Re^2: Bareword "FILE" not allowed while "strict subs"
by revdiablo (Prior) on Oct 08, 2004 at 22:59 UTC
    The use of file handle values in specific variables as BUU and bpphillips demonstrated is the most explicit way for everyone to know what is meant, for _all_ uses.

    I am not necessarily recommending its use here, but you seem to be overlooking the *foo{THING} syntax. The filehandle part of a typeglob can be gotten to directly by saying *FH{IO}. Here's a simple demonstration:

    $ perl -le 'open TODO, "TODO"; print *TODO{IO}' IO::Handle=IO(0x81637f0)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://397787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-04-21 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls