--- Teresa Raymond <[EMAIL PROTECTED]> wrote:
> I am receiving the error: # Global symbol "in" requires explicit package name.
> File 'Hard Disk:Desktop Folder:DOCS:CWN:ADS UPLOAD:ademail.cgi'; Line 14
...
> I don't understand how I am supposed to correct this error, I tried
> declaring with main::in, my $in but am only continuing to get the
> error msg.
...
> #!/usr/local/bin/perl -w
> use strict;
> use CGI qw(:all);
> $CGI::POST_MAX = 1_048_576; # 1 MEG FILE SIZE LIMIT
>
> ReadParse();
>
> print header;
>
> my $cgi = CGI->new;
> my $file = $cgi->upload( "ad" ) or error( $cgi->p( "No file uploaded." ) );
> my $format = $cgi->uploadInfo( $file )->{ 'Content-Type' };
>
> foreach my $i (keys%in)
> { print "$i\n";
> }
For you code, CGI.pm has a ReadParse method that allows you to have backwards
compatability with
cgi-lib.pl, but you need to explicitly import the function with:
use CGI qw/:cgi-lib/;
Since you are using the object oriented interface - $cgi->upload() instead of upload()
-, you
don't need ':all' and I have left it out of the statement. Also, :all does not import
the
cgi-lib.pl functions (ReadParse PrintHeader HtmlTop HtmlBot SplitParam Vars) as they
are only
included for purposes of backwards compatibility.
The reason that %main::in did not work is because that explicitly creates an %in hash
in the
'main' namespace. Declaring 'my %in' makes a lexically scoped variable that's private
to the
block or file that it's declared in. They are not the same thing. The reason you can
use
CGI::ReadParse and not declare the %in hash is because CGI::ReadParse exports this
hash into the
same namespace that the calling routine exists in. This is a bad practice, but the
author did
this to maintain backwards compatibility with CGI.pm (though cgi-lib.pl only exported
%in to main,
if I recall correctly).
Side note: unless you are trying to upgrade legacy code, don't use ReadParse. There
are a lot of
problems with using it and it's good to get used to making $cgi->param calls for
everything. To
duplicate your final loop, you could do this (which also prints the value associated
with each
param):
foreach my $name ( $cgi->param ) {
print "$name\t" . $cgi->param( $name ) . "\n";
}
Cheers,
Curtis Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/