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

This LOOKS right to me, why does it say the variables aren't explicitily called?
Global symbol "$alltheweb_c" requires explicit package name at popular +ity.pl line 399. Global symbol "$hotbot_c" requires explicit package name at popularity +.pl line 399. Global symbol "$lycos_c" requires explicit package name at popularity. +pl line 399. Global symbol "$msn_c" requires explicit package name at popularity.pl + line 399. Global symbol "$teoma_c" requires explicit package name at popularity. +pl line 399. Global symbol "$alltheweb_c" requires explicit package name at popular +ity.pl line 403. Global symbol "$hotbot_c" requires explicit package name at popularity +.pl line 403. Global symbol "$lycos_c" requires explicit package name at popularity. +pl line 403. Global symbol "$msn_c" requires explicit package name at popularity.pl + line 403. Global symbol "$teoma_c" requires explicit package name at popularity. +pl line 403. Global symbol "$alltheweb_c" requires explicit package name at popular +ity.pl line 407. Global symbol "$hotbot_c" requires explicit package name at popularity +.pl line 407. Global symbol "$lycos_c" requires explicit package name at popularity. +pl line 407. Global symbol "$msn_c" requires explicit package name at popularity.pl + line 407. Global symbol "$teoma_c" requires explicit package name at popularity. +pl line 407. Global symbol "$alltheweb_c" requires explicit package name at popular +ity.pl line 411. Global symbol "$hotbot_c" requires explicit package name at popularity +.pl line 411. Global symbol "$lycos_c" requires explicit package name at popularity. +pl line 411. Global symbol "$msn_c" requires explicit package name at popularity.pl + line 411. Global symbol "$teoma_c" requires explicit package name at popularity. +pl line 411. Global symbol "$alltheweb_c" requires explicit package name at popular +ity.pl line 415. Global symbol "$hotbot_c" requires explicit package name at popularity +.pl line 415. Global symbol "$lycos_c" requires explicit package name at popularity. +pl line 415. Global symbol "$msn_c" requires explicit package name at popularity.pl + line 415. Global symbol "$teoma_c" requires explicit package name at popularity. +pl line 415.
my $count = 0; foreach (keys %default) { my ($url_c, $altavista_c, $alltheweb_search_c, $hotbot_search_c, $lycos_search_c, $msn_search_c, $teoma_search_c, $total_c) = sp +lit (/\|/, $default{$_}); $count++; if ($total_c > 10000) { $group5{"$count"} = "$url_c|$altavista_c|$alltheweb_c|$hotbot_c| +$lycos_c|$msn_c|$teoma_c|$total_c"; } elsif($total_c > 5000 && $total < 10000) { $group4{"$count"} = "$url_c|$altavista_c|$alltheweb_c|$hotbot_c| +$lycos_c|$msn_c|$teoma_c|$total_c"; } elsif($total_c > 2000 && $total < 5000) { $group3{"$count"} = "$url_c|$altavista_c|$alltheweb_c|$hotbot_c| +$lycos_c|$msn_c|$teoma_c|$total_c"; } elsif($total_c > 750 && $total < 1000) { $group2{"$count"} = "$url_c|$altavista_c|$alltheweb_c|$hotbot_c| +$lycos_c|$msn_c|$teoma_c|$total_c"; } elsif($total_c < 750) { $group1{"$count"} = "$url_c|$altavista_c|$alltheweb_c|$hotbot_c| +$lycos_c|$msn_c|$teoma_c|$total_c"; } }

Replies are listed 'Best First'.
Re: variable issues (they are mean)
by davido (Cardinal) on May 15, 2004 at 05:51 UTC
    Take a closer look. You're declaring lexicals that have names like "$alltheweb_search_c", but then you're actually using variables that have names like "$alltheweb_c". Where are the variables without "_search" in their names being declared?


    Dave

Re: variable issues (they are mean)
by graff (Chancellor) on May 15, 2004 at 07:07 UTC
    So, apart from figuring out how you really want to spell your variable names (and let me just whisper: "make'em a little shorter"), I think you could simplify the code a lot by using an array of "group" hashes, instead of five completely separate hashes.

    BTW, is your intention to test just the value of "$total_c", or just the value of "$total"? Looking at the code, it seems odd to have a test like  $total_c > 750 && $total < 1000 )

    Anyway, I'll suggest an alternative that involves less "copy-and-paste" programming. The bad thing about copy-and-paste programming is that when you make one mistake, it turns into lots of mistakes in lots of places. Whenever you find yourself pasting the same code multiple times and changing the same point in each copy, you should be writing a loop or a subroutine instead, so that a given line of code really shows up only once. Oh, and I just noticed that all those copies of those variable names are unnecessary -- even the initial declarations -- because you only use the "$total_c" value from the "default" string, and then assign the original "default" string to some hash element -- you never really seem to do anything useful with all those variables.

    So here's something equivalent to what your posted code was trying to do (this alternative has not been tested):

    my $count = 0; for ( values %default ) # don't really need to know the keys { $count++; my $total_c = substr( $_, rindex( $_, '|' )+1 ); # assume that "group" is an array of hashes: my $groupid = 0; for my $limit ( 750, 1000, 2000, 5000, 10000 ) { if ( $total_c < $limit ) { last; } else { $groupid++; } } $group[$groupid]{$count} = $_; }
    Now, I realize that changing from "%group1, %group2, ..." to  %{$group[0]}, %{$group[1]}, ... might cause a major design shift in your code, might cause a lot of rewriting and rethinking, might even seem a bit tedious.

    But on the whole, the net effect will be to end up with less code -- you'll be deleting relatively lots of unnecessary code, and adding relatively little or none. It'll be time well spent, because it will translate directly into less time spent later, when you need to debug, maintain, update or enhance the code.

    (I'm still a bit doubtful about what this code is trying to accomplish, but perhaps that will be for another post...)

Re: variable issues (they are mean)
by tachyon (Chancellor) on May 15, 2004 at 05:56 UTC

    You are running with strict. Perl is telling you that you are using variables that have not been explicitly declared anywhere. Read the errors. Look at the varnames closely. Read the varnames you declare (and assign to)ie "$alltheweb_search_c" but THEN YOU USE "$alltheweb_c".....

    Fix the errors and the error messages warning you will go away.

    cheers

    tachyon

Re: variable issues (they are mean)
by Belgarion (Chaplain) on May 15, 2004 at 05:51 UTC

    Just quickly looking at the code shows that you're not consistent in your naming. For example, at the top of the loop you define $alltheweb_search_c, but then use $alltheweb_c (notice without the _search.) Try fixing your naming of variables.

Re: variable issues (they are mean)
by Zaxo (Archbishop) on May 15, 2004 at 05:50 UTC

    You are useing strict without declaring variables within their scope.

    After Compline,
    Zaxo