Why does my Perl script complain about the "global symbol" $ connection "requires an explicit package name"?

my $now = &GetDate;
my $myHeader = &ReadMessage;
my $mySoftwareVersions = param('mySoftwareVersions');
my $q = new CGI;print $q->header();

use CGI::Carp(fatalsToBrowser);
getAllSoftwareVersions();

sub getAllSoftwareVersions
{
        my $user = "zxxx";
        my $passwd = "xxxx";
#       my $tableName = "config_table";
#       my $connection = DBI->connect("DBI:mysql:MESCI:hamysql02.stl.mo.boeing.com:18080", $user, $passwd, { AutoCommit => 0, RaiseError => 1}) or die "Couldn't connect to Database: " . DBI->errstr;
        print "Must be connected\n\n";
        print "\n\n";
# Error here.
        my @Rows = &getConfigTableRows($connection, $config_table, $mySoftwareVersions );
        my $total = @Rows;
        print "total is ";
        print $total;

The above code dies with:

Global symbol "$ connection" requires explicit package name

Edit This question is related to:

I hope the original poster can clear it, so it makes more sense, but here is what we have, so we can try to help.

+3
source share
3 answers

, , $connection ( "" ) . perl , .

Raw Perl , undefined, . , strict - ( ), , . ( " " ), , , , , ,

Perl my, , our, .

my $connection = "Rainbow";

our $connection = 'French';

</" > , , , ​​ , . .

{ no strict;
  my @rows = getConfigTableRows( $nothing, @other_stuff ); 
}

Perl , $nothing . . , $connection , :

{ no strict;
  my @rows = getConfigTableRows( $connecion, $config_table, $mySoftwareVersions );
}

Perl '$connecion' , , , , 30 , , , - .

+3

, ,

, , , , .

, ?

+1

Re:

my $now = &GetDate;
my $myHeader = &ReadMessage;

, , :

my $now = &GetDate();
my $myHeader = &ReadMessage();

( ) , .

, cgi script mod_perl,

my $now = &GetDate( Apache2::RequestUtil->request );

, , , GetDate .

+1

Source: https://habr.com/ru/post/1705356/


All Articles