in reply to Re: 'return:' instead of 'return'
in thread 'return:' instead of 'return'

"Useless use of a constant in a void context"

Sorry, that's an artefact of my test code, actually what he was doing is more like:
sub cmd { my ($cmd) = @_; $cmd =~ s/\//\\/ig; my $ret = system($cmd); return: $ret; }
which is horrible for other reasons, but it doesn't produce the above warning. It was only thanks to perltidy that I noticed that there was something funny going on on the last line.


- Boldra

Replies are listed 'Best First'.
Re^3: 'return:' instead of 'return'
by bart (Canon) on Jun 12, 2009 at 09:36 UTC
    but it doesn't produce the above warning
    That is because in your code, it's the last statement in the sub. So by default, it's the value that is returned, even without a real return.
      And the last statement in a sub seems to be excluded from 'useless use of constant' warnings, I didn't know that.

      However, the other reason I didn't see "Useless use of a constant in a void context" is that my colleagues code has a variable (not a constant) after the 'return:'.


      - Boldra
        And the last statement in a sub seems to be excluded from 'useless use of constant' warnings, I didn't know that.

        It's not exclude. The reason why you don't see this warning, is because a constant as the last statement in a sub is not useless at all.

        -- 
        Ronald Fischer <ynnor@mm.st>
        However, the other reason I didn't see "Useless use of a constant in a void context" is that my colleagues code has a variable (not a constant) after the 'return:'.
        So you would have seen a "Useless use of a variable in void context" warning instead.