http://www.perlmonks.org?node_id=957683


in reply to Contextual::Return and Want, any major difference?

Want dispatches based on immediate context, whereas Contextual::Return dispatches based on first use. Example:

#!/usr/bin/perl use warnings; use strict; use Contextual::Return; use Want; sub foo_want { if (want('HASH')) { return { foo => "bar" } } else { return "Hello" } } sub foo_ctx { return HASHREF { { foo => "bar" } } DEFAULT { "Hello" } } print foo_ctx()->{foo}, "\n"; print foo_want()->{foo}, "\n"; my $ctx = foo_ctx(); my $want = foo_want(); print $ctx->{foo}, "\n"; print $want->{foo}, "\n";

And the result

$ perl /tmp/test.pl bar bar bar Can't use string ("Hello") as a HASH ref while "strict refs" in use at + /tmp/test.pl line 22.

In the second case, Want "fails" because it was not called in hashref context.

Note: rreturn only needed in :lvalue subs

Update: Showed that the want code works when used inline.

Good Day,
    Dean