On Tuesday, January 20, 2004, at 10:34 AM, B McKee wrote:

Hi All,
I'm having trouble understanding what use strict is trying to tell me.
If I have run this program
...snipped
open(MESSAGE, "$datafile") or die "Cannot open datafile: $!";
while (!eof(MESSAGE)) {
    $page = new CGI(MESSAGE);
...more snippage
I get this
-RESULTS------------------------------------------
Bareword "MESSAGE" not allowed while "strict subs" in use at ./errorprog.pl
line 16 (#1)
(F) With "strict subs" in use, a bareword is only allowed as a
subroutine identifier, in curly brackets or to the left of the "=>" symbol.
Perhaps you need to predeclare a subroutine?
...more snippage
My questions are:
1) Why is it warning me at all? Using a bare word in the filehandle is common
in my Perl manuals. In this case a bare word does everything I need it to do.
What is this warning trying to prevent?
2) If I replace MESSAGE with $filehandlename and add $filehandlename to the my () block
it doesn't complain. If I do that I haven't assigned a value to $filehandlename.
Does that mean my filehandle is actually 'undef'?
That doesn't seem right somehow, especially if I have multiple files open in
a different circumstance. What value should I assign to $filehandlename? MESSAGE?

Yep, I'm replying to my own post.


I have now also determined that quoting the word 'MESSAGE' above
e.g. open('MESSAGE', "$datafile")
clears the error. I guess use strict is trying to make sure I
didn't actually mean to use some sort of variable.
This is how I think I'll proceed in this case. I don't need to ever
change the value of the filehandle in this subroutine.
-->side note: I gather the "" around $datafile are kinda pointless too.....
Brian



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to