in reply to Re^2: On Foreach Loops and Maintainability
in thread On Foreach Loops and Maintainability

Is there a reason that the idea merlyn mentioned (that I think is a excellent use of perl) was comprehensively glossed over?

I'd also try and do away with the if block but I think cond or next; reads a little unintuatively and would probably use
next unless cond;

for ( 'arg1' .. 'arg5', "arg19", 'gee13' .. 'gee37' ) { next unless $object->method( $_ ); # do stuff }

Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re^4: On Foreach Loops and Maintainability
by Aristotle (Chancellor) on Oct 11, 2002 at 21:25 UTC
    It depends on what I want to emphasize: I use EXPR or next; when a failure at that point is the exception. Of course, looking back at the original poster's code, there's nothing that says it is - and if not, I agree, I'd use a next if. I do so 95% of the time anyway. The flexibility of Perl's syntax allows a natural way of conveying emphasis, and I try to make use of that when appropriate. "Self explanatory" is usually my top goal.

    Makeshifts last the longest.