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

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.

Replies are listed 'Best First'.
Re^3: More efficient dereferencing of a subroutine return
by frozenwithjoy (Priest) 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
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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019232]
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)
[Corion]: Two-way data binding means that if you change something in a text box, the corresponding variable in your Javascript gets updated immediately as well, and if you then change the variable, the corresponding text box also gets updated
[Corion]: That is a horrible approach that was also taken by Access, but if you have hooks that prevent automatic saving to the database, it is incredibly handy

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2017-03-30 07:52 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.