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

i'm crying uncle - what am i doing wrong? the $lowercase variable will contain only one mixed-case word. have i created a hash by mistake or what? i've predeclared my variables but i'm getting an error message saying i haven't predeclared $lowercase:
my $lowercase = (ucfirst(lc$infodir1)); if $infodir1 = $lowercase { #this is line 55 print $lowercase; } here's the error message: syntax error at d:\209.35.163.243\cgi-bin\getprods.pl line 55, near "i +f $infodir1 " Global symbol "%lowercase" requires explicit package name at d:\209.35 +.163.243\cgi-bin\getprods.pl line 55.

Replies are listed 'Best First'.
Re: case & sleep_deprivation=$crap
by Dog and Pony (Priest) on Apr 07, 2002 at 22:22 UTC
    Try:
    if ($infodir1 eq $lowercase)
    If you meant numerical comparison, you would also need to use double equal signs, ==, instead of just one. What you are doing now is an assignment. And thus, perl thinks that $lowercase{ .... } is meaning a hash element.
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
You're missing () around $infodir
by RMGir (Prior) on Apr 07, 2002 at 22:24 UTC
    Missing parens...
    if $infodir = $lowercase { print $lowercase; }
    is a conditional based on the value of a lookup in hash %lowercase (with the key being the return value of print, I think). It's also a numerical compare, as was pointed out above.
    if($infodir eq $lowercase) {print $lowercase; }
    is what you want. The () let perl figure out that $lowercase is a scalar, and not the start of a hash lookup.

    Besides, the prefix form of if always needs parens, doesn't it?
    --
    Mike

    (Edit: Missed the = part, I need a large code font I think... Time to learn CSS :))

Re: case & sleep_deprivation=$crap
by I0 (Priest) on Apr 07, 2002 at 22:25 UTC
    Perhaps you meant:
    if( $infodir1 eq $lowercase ){ print $lowercase; }
Re: case & sleep_deprivation=$crap
by Sweeper (Pilgrim) on Apr 08, 2002 at 05:41 UTC
    Another possible answer is

    Wait for Perl 6!.

    In Perl 6, parentheses around conditional will be optional, but at the same time, whitespace between a hash name and the open brace is forbidden. It seems that you are already using that...

    Speaking for myself, I am used to surround conditions with parentheses, but I will gladly discard them when Perl 6 comes.

    See Apocalypse 4 http://www.perl.com/pub/a/2002/01/15/apo4.html?page=2#rfc 022: control flow: builtin switch statement (and do not be confused by the paragraph title, this paragraph is also about parentheses and braces).

Re: case & sleep_deprivation=$crap
by malaga (Pilgrim) on Apr 07, 2002 at 22:35 UTC
    got it, thank you very much.