in reply to Re: check possible combination of sum using given array
in thread check possible combination of sum using given array

O.K. Just some nitpicking: I just wondered if your sub find {# bla ...; return} compiles. Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re^3: check possible combination of sum using given array
by Athanasius (Archbishop) on Jul 09, 2019 at 06:27 UTC

    Hello karlgoethebier,

    I just wondered if your sub find {# bla ...; return} compiles.

    Are you thinking of the missing semicolon? From perlsyn#Simple-Statements:

    Every simple statement must be terminated with a semicolon, unless it is the final statement in a block, in which case the semicolon is optional.

    Or were you worried about having a return without an explicit return value? From return:

    If no EXPR is given, returns an empty list in list context, the undefined value in scalar context, and (of course) nothing at all in void context.

    The only call to find in bliako’s script is find($T, \@input, $target, \@solutions);, which is a call in void context. So the bare return simply causes find() to exit immediately, by-passing the rest of the code in the subroutine.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Thanks for the explanation. I forgot that a sub is a block. Or can be regarded as a block. I didn’t worry about the "plain" return. Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re^3: check possible combination of sum using given array
by bliako (Abbot) on Jul 08, 2019 at 21:49 UTC

    Do you mean returning from sub without any explicit return value? e.g. sub { return; }

    obviously it did run but whether it's a faux-pas I have no idea! After all "It's your language. I'm just trying to use it.". Victor Borge via a very dear friend who was paraphrasing it as "It's your language. I am only using it."

      Sorry for the wisenheimerei. See my reply to Athanasius below. Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        I have just learnt a new word, thanks! but a word totally irrelevant here AFAIC.

        My motivation was to exit the sub in the most efficient way, the equivalent of C's  void sub(){ ... return; }. But there are contexts in Perl ... so perhaps return undef; or return 0; is a better/more efficient way. If not, then at least as far as showing intentions, it must be better. So, your remark was beneficial to me.