http://www.perlmonks.org?node_id=16275

nashdj has asked for the wisdom of the Perl Monks concerning the following question:

I was sitting around with nothign to do today. So I figured I would just play around with perl, and play around I did.

But I came across a few things, that I'm not sure if you can do. Well, sure there are other ways of doing the same, but the way I wanted to do some things, seemed to make a lot of sense and was simpler.

Firstly, $foo = ("this $foo" =~ s/a/b/); Well that obviously wont work because for one thing it is trying to modify a static string, and secondly because what we are actually placing into $foo at the end is the number of substitutions.
But why cant we modify a static string, sure it is "static" but if during execution perl creates a (non existant) variable to store it in. Do I make any sense, probably not. :)
The second step, assigning the actual result back to $foo, is there a way to do that (no I mean, is there a perlvar to set which causes it to do what I want)?

Next, I often find myself assigning a value to $_. Simple to do "$_ = $foo;" but I see that too much. What I was thinking would be nice was simply... $foo; Which by itself seems to serve no purpose, other than being usefull in a sub as a return. Again, am I missing something, is there a shorthand "$_ =" already?

Ok and for my last wish :) (no no, two actually)
Occasionally I find myself in a for (well foreach rather) loop, and want to find the previous value of $_
for(@_) { $in .=' '.($t = $_ - $last); $last = $_; }
Which can be done like that, but.. What I had in mind, was treating $_ as a stack. Each time it takes on a new value the stack is pushed up. The previous value could be given the name $__ then $___ and so on, but that could get very messy :) (does perl have something similar already?)...
Finally, as you see above I was using a for(@_) loop. Pretty short to do, but again... :) Does a standalone "for" do anything? I thought it would be nice if for{} == for(@_){}.

So there you have it, am I crazy, is all this already here. If not are there reasons why, or do you think they should be.