Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code snippet. But I want to avoid the warning. Any tips?

Exiting subroutine via next at test.pl line xx

#!c:\perl\bin\perl -w use strict; use File::Find; my $inputDir = $ARGV[0]; find {wanted => \&action, no_chdir => 1}, $inputDir; exit 1; sub action{ next unless m/.txt$/i; my $path = $_; #$File::Find; print "$path\n"; }

Replies are listed 'Best First'.
Re: suppress warning: Exiting subroutine via next
by pg (Canon) on Oct 30, 2003 at 02:43 UTC

    This is not the normal way to exit a sub. If you try to exit a sub via last, a similar warning would be produced:

    Exiting subroutine via last at a.pl line nnnn

    It is not a good idea to suppress a valid warning. You are simply cheating on yourself.

    The style you are getting into can easily introduce bugs. This is the same as using goto. You are altering execution path in a unstructured way.

Re: suppress warning: Exiting subroutine via next
by shenme (Priest) on Oct 30, 2003 at 02:33 UTC
    What's wrong with using return?
    return unless m/.txt$/i;
Re: suppress warning: Exiting subroutine via next
by Anonymous Monk on Oct 30, 2003 at 02:31 UTC
    Found the solution. Just replace the following line:

    next unless m/.txt$/i;

    with

    return unless m/.txt$/i;