Home: Perl Programming Help: Beginner:
Can't call method "header" on an undefined value at /.../login.pl line 19.



ningji
User

Jan 14, 2013, 8:43 AM


Views: 3097
Can't call method "header" on an undefined value at /.../login.pl line 19.

Can't call method "header" on an undefined value at /.../login.pl line 19.

# process the form
if($usr eq "demo" and $pwd eq "demo")
{
$session = new CGI::Session();
print $session->header(-location=>'index1.pl');
}


This is the sample i copied from web, what does this error mean pl ?
Attachments: login.pl (0.92 KB)


rovf
Veteran

Jan 15, 2013, 2:05 AM


Views: 3087
Re: [ningji] Can't call method "header" on an undefined value at /.../login.pl line 19.

It would mean that $session is undef. You could write explicitly


Code
$session = new CGI::Session() or die "Can not create CGI::Session object";


to be sure.


rovf
Veteran

Jan 15, 2013, 2:07 AM


Views: 3086
Re: [ningji] Can't call method "header" on an undefined value at /.../login.pl line 19.

BTW, have a look at perldoc CGI::Session:


Constructor. Returns new session object, or undef on failure. Error message is accessible through errstr() - class method.



ningji
User

Jan 15, 2013, 7:43 AM


Views: 3076
Re: [rovf] Can't call method "header" on an undefined value at /.../login.pl line 19.

errstr( ) gives error message, great !

new(): failed: couldn't load CGI::Session::Serialize::default: Can't locate Safe.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/share/perl/5.10/CGI/Session/Serialize/default.pm line 6.
BEGIN failed--compilation aborted at /usr/share/perl/5.10/CGI/Session/Serialize/default.pm line 6.
Compilation failed in require at (eval 7) line 3.


The problem is i cannot find Safe.pm.
I downloaded Session.pm from
http://packages.debian.org/stable/perl/libcgi-session-perl

Anyone knows where Safe.pm is ?


In Reply To
BTW, have a look at perldoc CGI::Session:


Constructor. Returns new session object, or undef on failure. Error message is accessible through errstr() - class method.



FishMonger
Veteran / Moderator

Jan 15, 2013, 9:15 AM


Views: 3072
Re: [ningji] Can't call method "header" on an undefined value at /.../login.pl line 19.

Safe.pm is a core module (Safe was first released with perl 5.002), which means that it should have been included in the base install of perl.

If it's not on your system, then I'd say that your perl installation is broken. You could use cpan to install the module, but if this core module is missing, the next question you should ask yourself is "what other core modules are missing?".


(This post was edited by FishMonger on Jan 15, 2013, 9:15 AM)