Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: More efficient dereferencing of a subroutine return

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

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

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; }

Replies are listed 'Best First'.
Re^4: More efficient dereferencing of a subroutine return
by parv (Priest) on Feb 18, 2013 at 00:05 UTC

    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

        It seems you and I read the representation of the problem differently. Your reply presumes that every return from sub is always a return of an array reference. (If that promise is made to the user of the sub, then I have no disagreement with direct dereferencing of the return value.) I think of the value returned being an array reference where possible; else, nothing or undef is returned.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019239]
[choroba]: erix Seems too complex
[erix]: do you mean: 'it can be done simpler', or 'it won't work' ?
[choroba]: I wouldn't want to maintain it in the current form
[erix]: ok, but mainainability comes after it has been made to work :)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2018-01-19 08:33 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (216 votes). Check out past polls.