Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Global symbol requires explicit package name

by Win (Novice)
on Nov 08, 2007 at 11:26 UTC ( #649688=perlquestion: print w/ replies, xml ) Need Help??
Win has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I get the following error message
Global symbol "%specifications" requires explicit package name at corr +elations.pl line 162.
with the following code
sub Diseases_of_concern { my $number_of_replicates = @_; my %specification = ( 'Disease A' => 'SC', 'Central_comparisons' => { 'Primary' => 'S', # x axis 'Secondary' => 'SC'} # y axis , 'Diseases to run against controls' => { 'First' => 'S', 'Second' => 'SC'} , 'Controls' => { 'A' => 'D', 'B' => 'LC' +, 'C' => 'COPD', 'D' => 'CHD' } ); my $x_axis_label = %specifications{'Central_comparisons'}{'Primary' +}; # Error specific to this line my $y_axis_label = %specifications{'Central_comparisons'}{'Secondar +y'}; # also this one
How do I fix that?

Update :
NB: Use warnings and use strict are used in my code.

Update B: I have fixed the stupid mistake and now I get the error message  syntax error at correlations.pl line 163, near "%specifications{"   Another stupid mistake I am sure

Comment on Global symbol requires explicit package name
Select or Download Code
Re: Global symbol requires explicit package name
by marto (Chancellor) on Nov 08, 2007 at 11:30 UTC
    Do you have use strict; use warnings; in your code? You have assigned values to %specification then query %specifications. You seem to have learned nothing from your years of asking questions such as (if not almost identical) to this here. Are you just trolling?

    Martin

    Update: 11:44am Win has updated his post with the following:

    "NB: Use warnings and use strict are used in my code.

    Marto failed to see the error"

    How can this be the case when I have pointed out what you have done wrong?
      Of course he's using use strict;, or otherwise he wouldn't get that error message.

      But apparently it's not clear to him what it means. I can't really blame him, I find this error message quite unclear myself. But after a long time of seeing this kind of error message, you eventually get used to it.

        Its not a pair of shoes. If you're using strict, read the documentation.
      You appear to be attempting to assign to a scalar from a hash key (also a scalar)
      Instead of: my $x_axis_label = %specifications{'Central_comparisons'}{'Primary'}; Try: my $x_axis_label = $specifications{'Central_comparisons'}{'Primary'};
      same for the second line.
      I'm a dev with serious background in Ja.. some other language and I was trying to understand a small program I found written in perl. Founding this kind of comment was like a signal to run away from Perl as fast and far as possible. Hopefully there are some other comments a bit friendler...

        Well I'm glad you're keeping things in perspective, judging a language based on one comment for which you have no context. I'm sure there are no posts relating to Java (or known trolls on Java forums) which could be taken out of context at all.

        You are missing context! If this was a remark to someone who just came to the site and was genuinely new to the language, it would definitely be way too harsh, but this was not the case. Win had been here since 2003 and well ... at times had been rather annoying. Now that wording of that error message is rather ... erm ... unfortunate, but after several years of programming in Perl ...

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.

Re: Global symbol requires explicit package name
by oha (Friar) on Nov 08, 2007 at 11:30 UTC
    you declared it without the final 's', but you use it with it.

    Oha

Re: Global symbol requires explicit package name
by blazar (Canon) on Nov 08, 2007 at 12:26 UTC
    %specifications{'Central_comparisons'}

    I personally believe that you're using Perl 6 already.

    Update B: I have fixed the stupid mistake and now I get the error message  syntax error at correlations.pl line 163, near "%specifications{"   Another stupid mistake I am sure

    Indeed, thus you would probably save yourself the humiliation of showing off as an asshole one who does so many stupid mistakes by doing what people has been recommending to you for years, namely: get familiar with some elementary Perl first.

Re: Global symbol requires explicit package name
by jdporter (Canon) on Nov 08, 2007 at 12:52 UTC

    Oh, that's easy to fix: learn Perl.

    In the meantime, I refer you to perldiag, where error messages are explained in rather more detail. You can get your perl process to emit "verbose" messages by adding use diagnostics to your program.

Re: Global symbol requires explicit package name
by cdarke (Prior) on Nov 08, 2007 at 14:08 UTC
    Update B: generally speaking, unless you are doing something 'clever': "a dollar on the left means a dollar on the right".

    When subscripting an array or a hash the leading character (sigil) does not indicate the type of the container but the type of the value. The braces {...} tells perl that it is dealing with a hash, the sigil indicates the context of what is inside the braces.

    Whoosh! (sound of slices passing over your head)
Re: Global symbol requires explicit package name
by Anonymous Monk on Feb 14, 2012 at 18:51 UTC
    Seriously Marto, you are really not very nice. Thank you Bart for being direct. Tired of these arrogant developer remarks. Just don't comment if you can't actually be nice, as well as helpful.
      I couldn't agree more. I found the use diagnostics very helpful. As for the rest, well we all have our areas of expertise which we can crow about, don't we..?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://649688]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-08-27 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (232 votes), past polls