tmatsumoto am Samstag, 13. August 2005 19.06:
> Hi,
>
> Thanks for the help. I've made the necessary changes. One error came up
> at runtime on the "use warnings;". I gather the module is not installed
> on the server I'm using.
Strange; the pragma module warnings.pm is AFAIK part of the core perl modules.
On my installation it is found at /usr/lib/perl5/5.8.6/warnings.pm.
> I've gone through and made changes to the
> script calling the package. I understand the syntax however the nothing
> is printed to the file.
Yes, you have another scope issue concerning %form_data, which is locally
defined within libcgi3.pm and thus gets out of scope at the end of
parse_input().
[See also zentara's answer. I myself have not yet switched to using "our"
much. Could be that the scope issue could elegantly be solved with "our",
e.g. with declaring %form_data in both files with "our" (in the top scope).
Oups.]
> Also I added use strict in the script which requires %form_data hash to be
> declared.
The two unqualified %form_data defined (in .pl and .pm) are different since
they reside in different packages; their full names would be
%main::form_data and %libcgi3::form_data.
> If I comment out use strict still nothing prints to the file.
One way to get it working: change the interface of parse_input(), so that it
returns the input-hash:
> libcgi3.pm
>
> package libcgi3;
>
> use strict;
> #use warnings; THE MODULE warnings.pm COULD NOT BE FOUND ON THE SERVER.
>
> sub parse_input {
> my $forminfo;
> my %form_data;
> my $whichmethod = $ENV{"REQUEST_METHOD"};
> if ($whichmethod eq "GET") {
> $forminfo = $ENV{"QUERY_STRING"};
> } else {
> $forminfo = <STDIN>;
> }
> my @key_value = split(/&/,$forminfo);
> foreach my $pair (@key_value) {
> my ($key, $value) = split(/=/,$pair);
> $value =~ s/\+/ /g;
> $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
> $form_data{$key} = $value;
> }
return \%form_data;
> }
[...]
> return 1;
> ------------------------------------------------------------------------
> -----------------
>
> writesurvey3.pl
>
> #!/usr/bin/perl -w
>
> #use strict;
>
> use libcgi3;
> libcgi3::parse_input();
> libcgi3::print_header();
> #my %form_data;
my $form_data=libcgi3::parse_input(); # hashref
>
> open (TOFILE,">infofile.txt") or die "Couldn't open file: $!";
>
> print TOFILE "$form_data{'favoriteurl'} \n";
print TOFILE "$form_data->{'favoriteurl'} \n"; # -> : dereferencing
hashref
> print TOFILE "\n\n\n";
>
> print TOFILE "$form_data{'reason'} \n";
print TOFILE "$form_data->{'reason'} \n";
> close(TOFILE) or die "Couldn't close file: $!";
>
> print "File infofile.txt successfully saved";
But I recommend using an existing module for the task of libcgi3.pm.
joe
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>