> -----Original Message----- > From: Nate Brunson [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 06, 2002 1:27 PM > To: [EMAIL PROTECTED] > Subject: lexical scopes vs. packages > > > ok so i didnt know who else to ask this question to... and it > doesent really have to do with cgi or anything im just wondering > say you have some code: > > sub read_input { > my ($buffer, @pairs, $pair, $name, $value, %FORM); > > $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; > if ($ENV{'REQUEST_METHOD'} eq "POST") { > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); > } else { > $buffer = $ENV{'QUERY_STRING'}; > } > @pairs = split(/&/, $buffer); > foreach $pair (@pairs) { > ($name, $value) = split(/=/, $pair); > $value =~ tr/+/ /; > $value =~ s/%(..)/pack("C", hex($1))/eg; > $FORM{$name} = $value; > } > %FORM; > } > > %fromweb = &read_input; > > now i was wondering in that code, if you 'use strict;' then > then it crashes... saying the packages are not found or > something.... but if you dont use strict; then it works.... > so my question is, is the %fromweb hash lexical to the > file... or is it put in the $main::main::fromweb, or whatever...??
%fromweb isn't a lexical. Lexicals are created with "my". It's a package global. Since there isn't a package statement, it lives in package main, so its full name is %main::fromweb. You can make 'use strict' happy by adding (at the top of the file): our %fromweb; Which leaves it a package variable, or: my %fromweb; which makes it a file-scoped lexical. Usually the latter is recommended. (P.S.: don't roll your own form parser; use CGI.pm or similar instead :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]