in reply to Good practice: Variable declaration

To comply with use strict on lexical scope, I reckon I need to start off with a variable declaration, which *doesn't* include an assignment: my $word;
No, you only need the my in there. Whether you assign something or not doesn't matter any. May I suggest though, that in your case it would be more readable to do it this way:
my $word = $part eq 'n' ? new Noun(@blah) : $part eq 'v' ? new Verb(@blah) : new Adjective(@blah); print $word->get_english();
Update: DOH! Ack. I don't know where I left my brain while I was posting the initial version of this. japhy++

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Good practice: Variable declaration
by japhy (Canon) on Jun 27, 2002 at 17:32 UTC
    Ouch. Remove those extra $word ='s. Not only are they assigning to a package-scoped $word, they're screwing up your ?: code. And you have a ":" where you want a "?", beneath the first "?".
    japhy% perl -MO=Deparse,-p my $word = $part eq 'n' ? $word = new Noun(@blah) : $part eq 'v' ? $word = new Verb(@blah) : $word = new Adjective(@blah);
    Check that out and you'll see that $word ends up getting assigned as an Adjective object no matter what, because of the precedence of ?: compared with that of =.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;