Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: on the fly reference to subroutine output

by Anonymous Monk
on Mar 04, 2013 at 19:45 UTC ( #1021703=note: print w/replies, xml ) Need Help??


in reply to Re^2: on the fly reference to subroutine output
in thread on the fly reference to subroutine output

The incorrect assumption here is that sub1 is returning an array.

In perl5, subs can return scalars or lists. Since it's not returning a (scalar) reference to an array, the only option is to store the list into a (possibly anonymous) array and pass a reference into sub2

tjd

  • Comment on Re^3: on the fly reference to subroutine output

Replies are listed 'Best First'.
Re^4: on the fly reference to subroutine output
by thirdm (Sexton) on Mar 05, 2013 at 05:28 UTC

    Ah, I'm always forgetting this.

    But underneath, is there a chance at some kind of return value optimization? Say if you have...

    sub1 { ... return @a; } $r = [sub1];
    Even if it's officially turning the values of @a into a list en route to copying them into the array that the brackets create a reference to, could perl not notice @a is no longer needed otherwise and instead simply make [sub1] be \@a behind the scenes? It would be neat if you could write sub1 that way instead of making it return \@a even if you anticipated the copy to be expensive.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021703]
help
Chatterbox?
[stevieb]: I've finally added the ability for berrybrew to fetch the list of perls available directly from Strawberry's releases.json file. Instead of pulling from there on every single call, I've added a berrybrew fetch, so it's only updated..
[stevieb]: ...on request. There's some supporting work I need to do, as well as update the docs, but it's in the v1.12 branch if anyone wants to play with it...
[stevieb]: ...issue 62 will track what else needs to be done.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-03-31 01:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (364 votes). Check out past polls.