John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

When running perl -c for a syntax check, I'm told that import is only used once, and the line it points to is *import= coderef();

First, how do I silence this warning during -c? It doesn't bother during a normal run, and I have "use warnings" on, so it's not a normal warning handled by the pragma.

Second, why does it let me refer to *import without declaring it first or qualifying it when use strict is in effect? Is it because it's a sub in this case, or are globs immune from the checking, or is import pre-declared?

Replies are listed 'Best First'.
(bbfu) Re: 'used once' during perl -c
by bbfu (Curate) on Nov 01, 2002 at 04:24 UTC

    Not 100% sure I'm not misunderstanding you, but...

    [johnsca@CORY tmp]$ cat tst #!/usr/bin/perl use warnings; use strict; sub foo { return 3 } *import = \&foo; [johnsca@CORY tmp]$ perl -c tst Name "main::import" used only once: possible typo at tst line 8. tst syntax OK [johnsca@CORY tmp]$ cat tst2 #!/usr/bin/perl use warnings; use strict; sub foo { return 3 } { no warnings; *import = \&foo; } [johnsca@CORY tmp]$ perl -c tst2 tst2 syntax OK [johnsca@CORY tmp]$ cat tst3 #!/usr/bin/perl use warnings; use strict; sub foo { return 3 } *blah = \&foo; [johnsca@CORY tmp]$ perl -c tst3 Name "main::blah" used only once: possible typo at tst line 8. tst syntax OK

    So, in summary, you can suppress the warnings with no warnings, and *import is not special, typeglobs are just exempt from use strict;.

    Hope that answers your questions.

    bbfu
    Black flowers blossum
    Fearless on my breath

Re: 'used once' during perl -c
by broquaint (Abbot) on Nov 01, 2002 at 13:31 UTC
    First, how do I silence this warning during -c?
    Just turn off that type of warnings for the given scope e.g
    { no warnings 'once'; *import = coderef(); }
    Or just mention it again in some way (according to perldiag).
    Second, why does it let me refer to *import without declaring it first or qualifying it when use strict is in effect?
    Because strict doesn't deal with globs. I think it's assumed if you're messing with globs you probably (and hopefully) know what you're doing.
    HTH

    _________
    broquaint

      When I use warnings, why does the 'once' warning only show up during a -c check, not during a regular run? Is the meaning of "use warnings" (with no parameters) different in these two cases?

        I'm afriad I'm unable to duplicate that here. I get the warning both when I -c it, and when I run it which, as far I as I know, is the correct behavior. This is with both ActiveState perl, and Cygwin perl.

        Perhaps you can post the code that's causes that behavior? You're not on 5.8.0, are you? Both of my perl's are 5.6.1. *shrug*

        (Output from my test below)

        bbfu
        Black flowers blossum
        Fearless on my breath