----
use Devel::Peek;
$a = 'Hi';
sub aa
{
local $_ = $_[0];
Dump($_);
}
sub bb
{
local *_ = \$_[0];
Dump($_);
}
Dump($a);
aa($a);
bb($a);
-----
For a sufficiently recent perl (tested on 5.24) the output will be
SV = PV(0x556a0e4dfb20) at 0x556a0e4fc7c8
REFCNT = 1
FLAGS = (POK,IsCOW,pPOK)
PV = 0x556a0e507250 "Hi"\0
CUR = 2
LEN = 10
COW_REFCNT = 1
SV = PV(0x556a0e4dfc00) at 0x556a0e4def48
REFCNT = 1
FLAGS = (POK,IsCOW,pPOK)
PV = 0x556a0e507250 "Hi"\0
CUR = 2
LEN = 10
COW_REFCNT = 2
SV = PV(0x556a0e4dfb20) at 0x556a0e4fc7c8
REFCNT = 2
FLAGS = (POK,IsCOW,pPOK)
PV = 0x556a0e507250 "Hi"\0
CUR = 2
LEN = 10
COW_REFCNT = 1
The aa subroutine creates a new scalar sharing the body of the other via
copy-on-write, the bb routine uses the passed scalar directly.
On older perls, aliasing in this way used to become faster than copying
the string for long strings (>> 100 characters). This is apparently
no longer the case when COW is supported.