Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^9: Experimenting with Lvalue Subs

by Juerd (Abbot)
on Jan 25, 2005 at 22:55 UTC ( #425076=note: print w/replies, xml ) Need Help??

in reply to Re^8: Experimenting with Lvalue Subs
in thread Experimenting with Lvalue Subs

I think juerd has posted a number of examples of where such behaviour would be very useful indeed. Hopefully he will reply with a link.

Just think of anything you can do with a variable, but cannot do with a value returned by a sub.

Variables are really powerful in Perl because they are mutable. While other languages disagree that this is a good thing (Python, for example, has immutable variables - only assignment can change a value), we should stick to the Perl idea that this can actually be put to great use.

Variables are variable, and that's where they excel. Some examples of what you can do on lvalues, but not on rvalues:

But really, my favourite:
  • you can take a reference and pass that, re-use that, etcetera!

To extend it to Perl 6, I'll explain how "." and ".=" work in P6: "." is used for method calls and dereferencing, as with "->" in Perl 5. ".=" is like Perl 5's ".=", except "." doesn't concatenate strings. If this is too vague, let one example be sufficient to explain what I mean: @array.=sort; does the same as @array = @array.sort, but possibly more efficient. No more need for LHS detection hacks like with the optimization for @array = sort @array; in Perl 5.

The expressiveness, flexibility and efficiency of lvalue operations must not be undersestimated.

Juerd # { site => '', plp_site => '', do_not_use => 'spamtrap' }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://425076]
NodeReaper patrols the perimeter

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2018-02-24 04:41 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.