in reply to a natural way of expressing things

spx2,
Typically, you would store the result of the long expression in a variable with a shorter name if you need to re-use the results in a number of later statements. That really isn't needed here but I have included it as it comes in handy.
my $name = $tree->ancestor->son->sibbling; if ($name =~ /john|jacob|jingle|heimer|smitz/) { # ... }
There are a number of different ways to check to see if the value is in a list. I provided a regex alternation but there is also grep or, for the truly bizarre, Quantum::Superpositions. Note: the alternation regex can be constructed using join.

Minor update regarding the reason why you store the result in a shorter variable.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: a natural way of expressing things
by Anno (Deacon) on Jul 09, 2007 at 11:45 UTC
    Alternatively a one-shot for loop can be used:

    for my $name ( $tree->ancestor->son->sibbling ) { if ( $name ... ) { # ... } # ... }
    Differences:

  • $name is scoped within the for block
  • $name is an alias of the original, not a copy

    Anno