in reply to Good practice: Variable declaration

That's fine. You could be spiffy and write it like:
my %class = qw( n Noun v Verb ); my $word = ($class{$part} || "Adjective")->new(...);
if you feel like being spiffy.

_____________________________________________________
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:??;

Replies are listed 'Best First'.
Re: Re: Good practice: Variable declaration
by Juerd (Abbot) on Jun 27, 2002 at 17:07 UTC

    That's fine. You could be spiffy and write it like:
    my %class = qw( n Noun v Verb );
    my $word = ($class{$part} || "Adjective")->new(...);

    Spiffier.

    my $word = ({ qw/n Noun v Verb/ }->{$part} || 'Adjective')->new(...);

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      I changed my code from that because that doesn't lend itself to repetition. Easier to change one data structure than many lines of code. Although I un-abstracted from what I had originally:
      my %class = qw( n Noun v Verb ); my $default = 'Adjective'; ...

      _____________________________________________________
      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:??;