in reply to default values for lists

try this:  @d = @a ? @a : @c;

Replies are listed 'Best First'.
Re: Re: default values for lists
by pike (Monk) on Sep 17, 2002 at 17:15 UTC
    OK, maybe I should have given more context: I was trying to strip of the ending of words, do something with the words and put the ending back on, like this:

    my ($end) = $word =~ /(e?s)$/ || (''); ... #do something with $word $word = "$word$end";

    If the word does not end in s/es, I get a warning about uninitialized variables where I append $end - which I wanted to avoid.

    I thought about the ternary, but I don't want to evaluate the regex twice.

    I simplified the problem because IMO it boils down to the question if I can enforce list context on the part before the ||. But maybe I oversimplified it.

    Thanks anyway for the suggestion.

    pike

      Ah, ok. Try this:

      ($begin, $end) = $word =~ /(.*?)(es|s|)$/;
      Then I'd say my $end = $word =~ /(e?s)$/ ? $1 : '';

      Makeshifts last the longest.