in reply to Is 'last' redundant in this code?

I'm wondering if 'last' is redundant if the call to the subroutine msg includes an 'exit'.
It is indeed redundant as it will never be reached, and I wouldn't be surprised if it was optimised out (see. Aristotle's reply on why this can't be done). It could be seen as self-documenting code, but it could be somewhat misleading and msg() should be documented denoting the fact that it exit()s when called. In fact, it looks a little like die(), so you might just want to use that instead e.g
foreach (@array) { die "Yes, key found\n" if /key/; }

HTH

_________
broquaint

update: extraneous semi-colon encountered a Backspace

Replies are listed 'Best First'.
Re: Re: Is 'last' redundant?
by Improv (Pilgrim) on Apr 07, 2003 at 13:45 UTC
    Back when I used to write a lot more C than I do now, I adopted the practice that if a function is not going to return, its name should have an and_die at the end, unless it's very obvious that it's not going to return (e.g. functions called "fatal", "die", or similar) This makes it impossible to miss. Of course, gcc also has some function attributes you can set that help the compiler optimize more in the case of never-returning functions..
Re^2: Is 'last' redundant? (can't be optimized)
by Aristotle (Chancellor) on Apr 07, 2003 at 14:21 UTC

    That cannot be optimized away. The compiler can't know what's going to happen at runtime - among others, things like overriding exit or msg..

    Note that you have an extraneous semicolon, btw.

    Makeshifts last the longest.