Rob Dixon wrote: > > Unless the $target variable was meant simply to decide on a return, it makes more > > sense to assign its value--one task, one line, and check it for validity--another > > task > > entirely, on a line of its own. > > So presumably you're against > > while ( my $line = <FH> ) { > : > } > > on the same grounds? :)
Only in cases where one is having trouble sorting out whether problems are arising from the assignment, or some aspect of the validation statement. It doesn't do any harm to take the extra line. > > > > The only thing it lacked was a meaningful return value. Since the getTarget > > function > > provided enough information to decide in favor of an early exit, this information > > should probably be passed on more explicitly, perhaps just by returning 0 rather > > than undef. > > I might buy > > ... this information could /possibly/ be passed on ... > > A simple > > return; > > is /explicitly/ not returning a value, which is fine. The fact that you get 'undef' > if you > use the subroutine call as a value is irrelevant. > > I don't believe a subroutine should always return a value just because it /can/. That > value is only useful if the calling code needs to behave differently depending on > the action of the subroutine. More often than not there's simply no point in passing > any value back to the calling code at all. Coding a return value that isn't used just > makes you look for subtleties that aren't there, and can lead (with the 'single exit > point' strategy) to the nightmare of dozens of subroutines which uselessly have a > 'return 1' as their final statement. I do wish though that there was a better > distinction > between returning control and returning a value. In Perl it's made slightly worse > because > you can have both a 'return' without a value and a value without a 'return' (on the > last > line of the subroutine). > > Cheers, > > Rob Agreed. The overall sense of the question, though, indicated to me that there is a lot going on in this function, and that it wouldn't hurt to provide any calling function with some indication of what went on inside. If the caller has no use for the return falags, then it can call in a void context. But this sense arises more from the apparent nature of the function than as a blanket rule. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]