Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Pointers and References

by bliako (Prior)
on Nov 23, 2020 at 13:10 UTC ( #11124061=note: print w/replies, xml ) Need Help??


in reply to Re: Pointers and References
in thread Pointers and References

Useful because it is a reminder that Perl doesn't need "output parameters" because it can return multiple values from a sub.

Correct. OTOH "output parameters" are also needed and very useful, for example when an existing huge array must be modified from within a sub.

Replies are listed 'Best First'.
Re^3: Pointers and References
by GrandFather (Saint) on Nov 23, 2020 at 20:08 UTC

    I don't really think of mutable arguments like that as "output parameters". "I/O parameters" maybe. I the sense that C like languages use output parameters where the sole job of the parameter is to return information from the function I don't see a need for output parameters in Perl, although passing references in the parameter list could be used that way.

    The run time and memory cost of returning a reference to a large structure, or a list of references to large structures has essentially the same overhead on Perl as passing references back as parameters. Since returning a list of stuff is natural in Perl returning a list of references makes for easier to understand code than working with output parameters.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      I have to say I come from C and back then (yes! Then) without goofle and the free literature it was a lot of hard work to conquer the pointers. I can't let it go now. I have often debated internally whether thinking in C while writing Perl was a good habit/idea/practice. It is NOT. But when %$^$& comes to shovel I have to think of some ways to make it faster. Because I am too lazy to program it in C eventually. And these are some of the tricks I pull.

      That's why my subs most of the times have a hashref of params as input (as opposed to array-style (file => 'aaa' , action => 'delete')) and I always return a hashref or arrayref or object back, but never ever an array. I think somewhere an angel dies when I do that. Cargo-culting perhaps, plus I am not a natural Perl-er.

      bw, bliako

        > ... as opposed to array-style ... but never ever an array ...

        Probably nitpicking: You say "array" but mean "list". :)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2021-06-15 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (70 votes). Check out past polls.

    Notices?