in reply to testing more than one item for equality
I'm trying to do the following:if ( ($item1 or $item2) eq ($item3) ) { #do something; }
Just use a junction. Oh no, Perl 5 doesn't have junctions. Well, then there's Quantum::Superpositions, but personally I wouldn't use it...
In fact I've had to workaround:my $result = grep { $_ eq $item3 } ($item1, $item2); if ($result) { #do something }
That's fine enough, has the advantage of having a straightforward generalization to more items and can be cast into a IMHO simpler form like thus:
if (grep $_ eq $item3, $item1, $item2) { #do something }
Is there a more direct statement one can use?
More direct?
if ($item1 eq $item3 or $item2 eq $item3) { #do something }
This has the advantage of or's short circuiting, but in this case it really seems like a micro-optimization not worth the effort. To generalize to an arbitrary number of items you'd better need a hyperoperator that's not in Perl 5 either.
|
|---|