Subject: | context |
Date: | Wed, 18 Feb 2009 18:40:50 +0100 |
To: | bug-Error-Return [...] rt.cpan.org |
From: | David Raab <d.raab [...] angel.de> |
Error::Return does not use the return context from is "upper" function.
Show quoted text
> use Error qw(:try);
> use Error::Return;
>
> print my_localtime(), "\n";
> print scalar(my_localtime()), "\n";
>
> print "\n";
>
> print my_localtime2(), "\n";
> print scalar(my_localtime2()), "\n";
>
> sub my_localtime {
> print wantarray() ? 'array' : 'scalar', ': ';
> return localtime();
> }
>
> sub my_localtime2 {
> try {
> print wantarray() ? 'array' : 'scalar', ': ';
> RETURN localtime();
> };
> }
If you have something like this then in my_localtime2 the context is still a list context but it returns only the first element.
Output of the above script can something like this:
Show quoted text> array: 640181811093480
> scalar: Wed Feb 18 18:40:06 2009
>
> array: 640181811093480
> scalar: 6