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

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.

Replies are listed 'Best First'.
Re^6: check possible combination of sum using given array
by karlgoethebier (Abbot) on Jul 11, 2019 at 14:44 UTC

    Wait. This is not about efficiency. I guess it’s more about what our founders used to call flexibility.

    I sometimes wrote things like this:

    sub nose { my $cuke = shift; 1 if $cuke; return; }

    This should work as well:

    sub nose { my $cuke = shift; 1 if $cuke; undef; }

    And i‘m pretty sure that you are aware that return undef; AKA return; isn’t the same as return 0;. But it may be that I even forgot this issue because of lack of practice.

    Code not tested because of vacation. Hence no warranty 🤪. 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

      > isn’t the same

      Even return and return undef aren't the same.

      sub plain { return } sub Undef { return undef } my @empty = plain(); my @nonempty = Undef(); die 'Different' unless @empty == @nonempty;

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Wow! (No kidding). This is jesuitisch raffiniert.

        I wonder what might happen when it’s sub kgb {undef}. 🤪 Probably nothing special. Works as designed. 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

        J