Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: bug or curly bracket hell?

by hippo (Bishop)
on Jan 13, 2023 at 16:45 UTC ( [id://11149573]=note: print w/replies, xml ) Need Help??


in reply to Re^2: bug or curly bracket hell?
in thread bug or curly bracket hell?

"Global symbol "%s" requires explicit package name" Can you give me some tips on fixing that?

You have chopped off the last part of the error message and that was the bit which explains how you can fix it.

$ perl -Mstrict -e '%s = ();' Global symbol "%s" requires explicit package name (did you forget to d +eclare "my %s"?) at -e line 1. Execution of -e aborted due to compilation errors. $ perl -Mstrict -e 'my %s = ();' $

See: my and our.


🦛

Replies are listed 'Best First'.
Re^4: bug or curly bracket hell?
by MoodyDreams999 (Beadle) on Jan 13, 2023 at 19:29 UTC

    okay lets say I have this code to access a server/database and I have repeating variables and these are the repeating errors I have on strict. Variable "$VARDB_DATABASE" is not imported AT PROJECT.PL LINE 43. I get this for the other variables as well then Global symbol "$VARDB_DATABASE" requires explicit package name AT PROJECT LINE 43. Keep in mind this works with out strict for me. (paragraph)

    #path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; @conf = <conf>; close(conf); my $i=0; foreach(@conf){ $line = $conf[$i]; $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) {$VARDB_database = $line; my $VARDB_database =~ s/.*=//gi;} if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} if ( ($line =~ /^VARDB_custom_user/) && ($CLIDB_custom_user < 1) ) {$VARDB_custom_user = $line; $VARDB_custom_user =~ s/.*=//gi +;} if ( ($line =~ /^VARDB_custom_pass/) && ($CLIDB_custom_pass < 1) ) {$VARDB_custom_pass = $line; $VARDB_custom_pass =~ s/.*=//gi; +} if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} $i++; } if (!$VARDB_port) {$VARDB_port='3306';} use strict; use warnings; use Excel::Writer::XLSX; use DBI; use Time::Piece; use Math::Round; my $t = "" . $i; my $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$ +VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr;
      if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) {$VARDB_database = $line; my $VARDB_database =~ s/.*=//gi;}
      With strict enabled you can't do certain things that make no sense, like declaring a variable with "my" after you already used that variable.
        Well I guess that means I will have to rewrite it all if I wanna use strict, thank you for the guidance

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found