in reply to An infix fix
I would have thought of creating a function which went through the list before the eval() usage in OP. In any case, and operation could have been easily implenented something like ...
# Adjust truth value tests & returned truth values as you like. sub short_circuit_list_and { my @list = @_; return unless scalar @list; my $and = 1; foreach my $i (@list) { return 0 unless $i; $and = $and && $i ? 1 : 0; } return $and; }
Am i seriously missing something?
UPDATE: I could not settle w/ the ternary operator inside the loop, so a variation ...
# Adjust truth value tests & returns as you like. sub list_and { my @list = @_; return unless scalar @list; my $and = 1; foreach my $i (@list) { return 0 unless $i; $and &&= $i; } return $and ? 1 :0; }
- Parv
|
|---|