Light Bringer
Light Bringer

Reputation: 829

Perl (use CGI) Can't call method "header" without a package or object reference

Alright, using Perl for the first time in a decade, sort of rusty. Thinking perhaps some updates since then (genius huh?)

Alrighty, This is Perl 5, version 16, subversion 3 x86_64-linux-thread-multi with 29 registered patches on AWS micro.

Perl came with it, I just yum installed perl-CGI perl-Data-Dumper

#!/usr/bin/perl
use CGI;                                        # load cgi routines
my $q = CGI>new;                                # cgi object
print   $q->header(),
        $q->start_html("Hello World"),
        $q->h1('Hello'),
        $q->end_html;
~

Seems about a simple and straightforward as it can be, as I build programs bit by bit. But I have got an error at if I run it at the command line (or browser).

Can't call method "header" without a package or object reference at create line 4.

Line 4 is the print $q->header(); "create" is the file name.

Any ideas? Bring me up to date in Perl 2017? My problems, being rusty are always something fabulously simple.

Upvotes: 0

Views: 175

Answers (1)

Dave Cross
Dave Cross

Reputation: 69314

Looks like a typo.

my $q = CGI>new;

should probably be

my $q = CGI->new;

Perl is interpreting your code as:

my $q = 'CGI' > 'new';

So you end up with a false value (probably an empty string) in $q. And you can't call methods on an empty string :-)

Upvotes: 5

Related Questions