malaga has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting an error that "$cgi" requires an explicit package. wouldn't that be 'use CGI qw/:standard/;'?
#!/usr/local/bin/perl use Data::Dumper; use strict; use CGI qw/:standard/; my $value = $cgi->param('value'); open FILE , "facultydummy.txt" or die "Cannot open: $!"; #my $rowid = $ARGV[0] || '$roy'; my $rowid = $ARGV[0] || 'value'; my %data = (); my @fields = split(/\t/, <FILE>); chomp @fields; while(<FILE>) { chomp; my @row = split(/\t/); if ($row[0] eq $rowid) { @data{@fields} = @row; last; } } print "Content-type: text/html\n\n"; if ( keys %data ) { # found, display data print Dumper \%data; } else { # not found, show error print STDERR "Can't find row '$rowid'\n"; }

Replies are listed 'Best First'.
Re: CGI PM
by Fastolfe (Vicar) on Jan 28, 2001 at 23:22 UTC
    You have not instantiated a CGI object. Either use the :standard interface and do not use the $cgi object, or create a new CGI object and forego the :standard interface:
    use CGI; my $cgi = new CGI; my $field = $cgi->param('field'); # versus use CGI ':standard'; my $field = param('field').
      thanks. i couldnt' get it to work the first way - with CGI, but the second way worked. well, my script isn't working, but the error is gone. :)

        Now that you have your cgi object, why not use the value you got from it? :)

        You maybe want to do:

        my $rowid = $ARGV[0] || $value ;

        instead of:

        my $rowid = $ARGV[0] || 'value';

        <kbd>--
        PerlMonger::Paris(http => 'paris.pm.org');</kbd>