Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: how to write a modified return() call?

by moritz (Cardinal)
on Jul 14, 2009 at 14:54 UTC ( [id://779942] : note . print w/replies, xml ) Need Help??


in reply to how to write a modified return() call?

That might be a bit overkill for your situation, but you could solve your problem with continuation passing, something along these lines:
sub resolve_value { my $start_with = another_value(); unless $start_with { warn "Could not get another value"; return; } my $continuation = shift; return $continuation->($start_with, @_); } # and here's how you use that code: sub foo { # do some work here resolve_value(sub { my $start_with = shift; # do the rest of the work here }) }

If you care about performance you could also tail-call into the sub:

goto &resolve_value(sub { ... });

Replies are listed 'Best First'.
Re^2: how to write a modified return() call?
by j1n3l0 (Friar) on Jul 15, 2009 at 10:52 UTC
    I think you've been spending too much time in Rakudo moritz ;)

    unless $start_with { ... } # missing "()" around $start_with


    Smoothie, smoothie, hundre prosent naturlig!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://779942]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-02-06 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found