in reply to Re: default values for lists
in thread default values for lists

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

Replies are listed 'Best First'.
Re: Re: Re: default values for lists
by fglock (Vicar) on Sep 17, 2002 at 17:33 UTC

    Ah, ok. Try this:

    ($begin, $end) = $word =~ /(.*?)(es|s|)$/;
Re^3: default values for lists
by Aristotle (Chancellor) on Sep 17, 2002 at 21:14 UTC
    Then I'd say my $end = $word =~ /(e?s)$/ ? $1 : '';

    Makeshifts last the longest.