in reply to Global symbol requires explicit package name

antirice and aquarium have answered the immediate question, as to why the code at line 23 generated that particular error. If you follow their advice and simply put  my %in; above that offending line, I can anticipate what your next posted question might be...

"Why do I get these warnings about 'use of undefined value at line 24'?" The uncooperative answer will be: "You added that extra line to declare %in, so the for-loop line is now line 24, and you are using the '-w' flag on the initial line of the script, which causes these warnings to be printed to stderr, and you have not assigned any values to the hash array %in, which is what those warnings are complaining about."

So, the next issue for you to address is: what is the hash array %in supposed to contain? Where are these contents supposed to come from? It seems that you expect this hash to have elements keyed by the various strings in the @param array, and since you are using the CGI module, you probably want %in to hold the names and values of parameters that come in from a web form, but you haven't got the code that is needed to put those values into %in.

The man page for the CGI module is very informative -- it's long, but it's worth the time you take to read it. That should make things clearer for you. Look especially at the part titled "FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER".

In your case, it might be best to ignore what the earlier replies suggested, and base your code on a better knowledge of the CGI module. In essence, you don't need a hash array:

$body .= param($_)."\n" for @param;
This uses the "function-oriented" style of CGI usage, calling the "param()" method to return the value of each parameter name, as supplied by the @param array.

update: personally, if I were expecting email from this sort of process, I would prefer that the email message include the parameter name on each line along with the parameter value:

$body .= join("", "$_ : ", param($_), "\n") for @param;
and of course, if any parameter name could be submitted with more than one value, I'd want the email to list all of the values, which could be done like this:
for my $p (@param) { my @v = param( $p ); $body .= join( "", map { "$p : $_\n" } @v ); }

Replies are listed 'Best First'.
Re: Re: Global symbol requires explicit package name
by Nickd_69 (Novice) on Aug 15, 2003 at 02:31 UTC
    You are a perl god. Of all the people you have been most helpful by far. Have got this error now but I don't think it would be too hard to solve. It is: Can't call method "close" without a package or object reference at enquiry02.pl line 36. It is referring to the line: $mailer->close; Any ideas?? What could be wrong with the line??
      I haven't used the Mail::Mailer module myself. Since you have it installed, you should be able to do "perldoc Mail::Mailer" to read about it (or lookup the man page at www.cpan.org).

      My initial guess would be that its "close" function is not "exported" to your script by default (though this would seem uncooperative); have you tried:

      use Mail::Mailer (qw/close/);

      update: having just looked at the docs on CPAN for Mail::Mailer, it may be that the correct means is:

      use Mail::Mailer qw(mail);
      Though why this should make a difference is beyond me. (This module is not exemplary in its documentation.) Anyway, you could also try just removing the "close" statement -- when the script exits, the mail object is bound to close.

        This is incorrect. Method calls do not need to be exported. That's the point!

        Besides that, that's never what the error message means.

        If you don't know an answer, please don't guess! Instead, look up the error message in perldiag and educate yourself before you lead people astray.

        The second line you just added gave me the same error but the first one worked. The only problem is the my web server doesn't have close.pm on it to close the mailer so I am trying to get them to put it on now. Pretty weird how the first one worked and the second didn't. At least the script finally works. (Well I hope!).