in reply to Re: bug or curly bracket hell?
in thread bug or curly bracket hell?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: bug or curly bracket hell?
by hippo (Bishop) on Jan 13, 2023 at 16:45 UTC | |
"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.
🦛 | [reply] [d/l] |
by MoodyDreams999 (Sexton) 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)
| [reply] [d/l] |
by Anonymous Monk on Jan 13, 2023 at 20:36 UTC | |
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. | [reply] [d/l] |
by MoodyDreams999 (Sexton) on Jan 13, 2023 at 21:52 UTC | |
by Anonymous Monk on Jan 14, 2023 at 01:00 UTC | |
Re^3: bug or curly bracket hell?
by GrandFather (Saint) on Jan 13, 2023 at 23:02 UTC | |
First off: 'code smells' are coding styles that are fragile or hard to maintain (probably because they are hard to read). use strict helps address some forms of code smell if used sensibly. One thing that can make a huge difference is to ensure variables are used in the smallest sensible scope - strict helps that by telling you where an undeclared variable is first used. A very closely related technique is to initialise scalar variables (variables that start with $) where they are declared. Sometimes array and hash variables can be usefully initialised where they are declared too, but often they are used to accumulate entries in following code and don't need an explicit initialisation value at declaration (they are born empty). The golden rule: Always use strictures (use strict; use warnings; - see The strictures, according to Seuss). Strictures, especially strict, tell you about things that are easy to get wrong and hard to find, like changing the spelling of an identifier. Using lexical variables (variables declared with my) limits their scope to the enclosing block (within the enclosing { } pair) which helps in understanding how variables are used and avoids misusing variables. Fixing a bad smell can often end up with a jolly good clean out of the whole fridge to everyone's benefit. Adopting the use of strictures is a good start to cleaning up smelly code.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] [d/l] |
by Bod (Vicar) on Jan 14, 2023 at 01:11 UTC | |
Adopting the use of strictures is a good start to cleaning up smelly code Absolutely seconded! I resisted at first but since following the teaching wise monks, my code has been less smelly, giving me an easier and more pleasant coding life. | [reply] |
by MoodyDreams999 (Sexton) on Jan 24, 2023 at 23:03 UTC | |
| [reply] [d/l] |
by kcott (Archbishop) on Jan 24, 2023 at 23:46 UTC | |
You have a bogus 'print "' at the start of your code. The closing quote for that string is 'open('conf', "' (many lines later). All of the apparent use statements and my declarations, in the intervening code, are just part of the string; they are not Perl statements that will be executed. — Ken | [reply] [d/l] [select] |
by GrandFather (Saint) on Jan 25, 2023 at 02:10 UTC | |
by kcott (Archbishop) on Jan 25, 2023 at 11:07 UTC | |
| |
by Anonymous Monk on Jan 24, 2023 at 23:40 UTC | |
my $PATHconf = '/etc/astguiclient.conf'; # declared and initialized my ( # declared with "my" but not initialized $PATHlogs, $VARserver_ip, $VARDB_server, $VARDB_database, $VARDB_user, $VARDB_pass, $VARDB_custom_user, $VARDB_custom_pass, $VARDB_port);You need to initialize your declared variables by defining their values: my $PATHconf = '/etc/astguiclient.conf'; my $PATHlogs = '/path/to/logs'; my $VARserver_ip = '1.2.3.4'; my $VARDB_server = 'your_db_server'; my $VARDB_database = 'name_of_database'; my $VARDB_user = 'the_db_username'; my $VARDB_pass = 'the_db_password'; | [reply] |