Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Just before subroutine returns

by Athanasius (Chancellor)
on Aug 29, 2017 at 06:32 UTC ( #1198247=note: print w/replies, xml ) Need Help??

in reply to Just before subroutine returns

Hello solegaonkar,

Try the End module. Here’s a trivial example:

use strict; use warnings; use End; foo(4); foo(6); sub foo { my ($n) = @_; my $x = end { print "\$n = >$n<\n" }; return 1 if $n < 5; $n *= 52; return $n; }


16:31 >perl $n = >4< $n = >312< 16:31 >

Note that the assignment to $x is needed here, because of the way End works, even though the value of $x isn’t used.

Hope that helps,

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

Replies are listed 'Best First'.
Re^2: Just before subroutine returns
by solegaonkar (Beadle) on Aug 29, 2017 at 06:58 UTC
    Yes! That worked.. Thanks for your help!

      If you need to know which return returned, you might be able to wrap return using Keyword::Declare or Filter::Simple.

      Be warned: These are very powerful, therefore dangerous to use.

        I'd recommend Keyword::Simple , but for completeness: a sub can be left without return.

        Possibilities include:

        • implicit return at body's end
        • goto label in caller chain
        • goto &sub
        • die exception

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re^2: Just before subroutine returns
by karlgoethebier (Monsignor) on Aug 29, 2017 at 18:21 UTC

    Even the command line to install it is pure fun:

    karls-mac-mini:monks karl$ cpanm End --> Working on End

    Thanks and 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1198247]
[Your Mother]: s/a /at /;
[LanX]: just watch the video ...
[Your Mother]: Roger, will co.
[Your Mother]: The good news is, they think they are influencing people but Americans at least are irretrievably biased. All that can be accomplished is a little spike in domestic violence. :P

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2018-03-19 13:25 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.