in reply to On References to the Unnamed

I noticed today that TheDamian posted another way to do it namely:

$anon_scalar_ref = \eval{undef}; # or ... $anon_scalar_ref = \eval{ $init_val }; # if you prefer anon scalar in +itialized

Running:

#!/usr/bin/perl use strict; use warnings; use Devel::Size 'total_size'; use Devel::Peek; my $a = \"$$"; my $b = \""; my $c = \do {my $foo}; my $d = \eval{undef}; print total_size($a), "\n"; print total_size($b), "\n"; print total_size($c), "\n"; print total_size($d), "\n"; print "-----\n"; print Dump($a); print Dump($c); print Dump($d);
produced:
29 25 12 12 ----- SV = RV(0x1865b28) at 0x18242d8 REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) RV = 0x224f08 SV = PV(0x2251fc) at 0x224f08 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1834234 "3484"\0 CUR = 4 LEN = 5 SV = RV(0x1865b30) at 0x18242e4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) RV = 0x186168c SV = NULL(0x0) at 0x186168c REFCNT = 2 FLAGS = (PADBUSY,PADMY) SV = RV(0x1865b34) at 0x18247a4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) RV = 0x224fbc SV = NULL(0x0) at 0x224fbc REFCNT = 1 FLAGS = ()