http://qs321.pair.com?node_id=684044


in reply to Re: Pass by ref vs alias : why does scalar size matter?
in thread Pass by ref vs alias : why does scalar size matter?

When I tried your example of changing s/\s+// to s/\s+/ / I still saw the decline in speed in the alias version, albeit more slowly. The ref version went from -40% to -20%.

I saw a similar (but varying) decline for these operations:

$_[0] .= 'abcde'; vs ${ $_[0] } .= 'abcde'; $_[0] = substr( $_[0] , -500); vs ${ $_[0] } = substr(${ $_[0] } , -500);

Presumably this has something to do with writing the value back to an alias?

Update: This is just wrong. When retesting this morning, I realised that, while the differences in speed between the two got closer together as the string grew, they never actually switched. Instead, it was just that the string operation took a proportionally greater part of the time, and thus the cost of using references was relatively less.

The only example I've been able to come up with where the two actually switched is the original version in Pass by ref vs alias : why does scalar size matter?