Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: More efficient dereferencing of a subroutine return

by parv (Priest)
on Feb 17, 2013 at 23:18 UTC ( #1019232=note: print w/ replies, xml ) Need Help??


in reply to Re: More efficient dereferencing of a subroutine return
in thread More efficient dereferencing of a subroutine return

Darn thing causes fatal error of Can't use an undefined value as an ARRAY reference if undef is received under strict 'refs', where the dereference result could have been an empty list without the need to invoke no strict ... . I will take the temporary variable to do a check first.


Comment on Re^2: More efficient dereferencing of a subroutine return
Select or Download Code
Re^3: More efficient dereferencing of a subroutine return
by Anonymous Monk on Feb 17, 2013 at 23:43 UTC
    what? Can you demonstrate that?
Re^3: More efficient dereferencing of a subroutine return
by frozenwithjoy (Curate) on Feb 17, 2013 at 23:48 UTC
    Can you show what exactly gives you that error? I get no errors/warnings with this:
    #!/usr/bin/env perl use strict; use warnings; use feature 'say'; my @result = @{ subroutine() }; say "@result"; sub subroutine { my @array = (); return \@array; }

      Did you, and the one before you, missed the part where I wrote about the case of undef being returned, as in ...

      use strict; my @p = @{ list() }; sub list { return undef; }

      ...?

        That is what you said, but look at the OP's code, its always  return \@array which can never be undef

        an empty array is better than undef

Re^3: More efficient dereferencing of a subroutine return
by tobyink (Abbot) on Feb 18, 2013 at 07:48 UTC

    In that case,

    my @ARRAY = @{ subroutine() || [] };
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-07-31 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls