in reply to strict problem

Regardless of other circumstances (such as using CGI.pm instead of lib-cgi.pl) here's how to define a global variable under strict:
#!/usr/bin/perl -w use strict; use vars qw/$my_very_own_global_variable_one $foo $three/; # rest of the script goes here..
Please consider reading some documentation on variable scope if you have any further questions..

octo

Replies are listed 'Best First'.
Re: strict and variable scopes
by oubiwann (Sexton) on Mar 20, 2002 at 16:12 UTC
    An important thing to keep in mind, is that you are defining a lexical variable with my @in. This means it will only be in scope within that block, unless you use a method like flocto mentions above. Though it can be useful to subvert perl (sometimes essential?), one should always consider what is really trying to be accomplished and whether that subversion is truly necessary.

    There may be a semantics problem here, too. One of the reasons that my was introduced to perl to was to give perl true local variabls, as local was a work around using a technique of substituting globals. What you would be telling perl is "please make this a local variable, but then don't be strict with me and let me use it anywhere I want without chiding me" (I hope that doesn't sound too harsh!). If you really want global variables, you probably want to use what perl terms as "package" variables:

    Instead of using my, you would declare the package that you are in (probably just "main" in this case) like so:
    $main::in = ...
    Hope that helps. By the way, there are all kinds of nodes here discussing local, my, our etc., and how various monks deal with scoping. Best of luck!
      An important thing to keep in mind, is that you are defining a lexical variable with my @in. This means it will only be in scope within that block, unless you use a method like flocto mentions above.

      But if I call an external procedure, won't this procedure inherit the environment of it's caller - and therefor all of it's variables be within the scope of that very block?

        Short answer: No, it won't.

        Long answer: It won't inherit lexical variables. That's the point. If you localize a global name, that change will be visible to all functions called within the scope of the change.

        That won't help you here, though, as you first need to declare a global name with the vars pragma.

Re: strict and variable scopes
by Anonymous Monk on Mar 20, 2002 at 18:08 UTC

    That actually worked... Thanks!

    I don't remember seeing something saying literally here's how to define a global variable under strict - which was all I needed to hear (for now).

    I'll read up on variable scoping soon, I'm just learning here... (like all of us, I suppose). Anyway, it wasn't clear to me after reading the docs at hand.

    See you around...