in reply to Getting an unknown error

$ perl -MDevel::Peek \ -e'$x="abc"; Dump($x); Dump($1); for $1 ($x) { Dump($1); }' SV = PV(0xd0e9e0) at 0xd2b810 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0xd33f20 "abc"\0 CUR = 3 LEN = 10 COW_REFCNT = 1 SV = PVMG(0xd23870) at 0xd36138 REFCNT = 1 FLAGS = (GMG,SMG) IV = 0 NV = 0 PV = 0 MAGIC = 0xd44e10 MG_VIRTUAL = &PL_vtbl_sv MG_TYPE = PERL_MAGIC_sv(\0) MG_OBJ = 0xd36120 MG_LEN = 1 SV = PV(0xd0e9e0) at 0xd2b810 REFCNT = 2 FLAGS = (POK,IsCOW,pPOK) PV = 0xd33f20 "abc"\0 CUR = 3 LEN = 10 COW_REFCNT = 1

Before the loop, the symbol $1 accesses the scalar at address 0xd36138.

Inside the loop, the symbol $1 accesses the scalar at address 0xd2b810, which is the same scalar accessed by $x.

The read-only property of $1 is a property of the scalar. At your own request, you are not accessing that scalar within the body of the loop.

The capture fetching property of $1 is a property of the scalar. At your own request, you are not accessing that scalar within the body of the loop.

Replies are listed 'Best First'.
Re^2: Getting an unknown error
by oiskuu (Hermit) on Apr 24, 2015 at 17:15 UTC

    Arguably, the lack of a warning is a bug here (at the very least).

    Note that the dynamic scoping of $1 appears to be a property of the scalar as well. Masking it over will break pretty much anything called from within that loop, but not only—signal handlers break too.

    $SIG{ALRM} = sub { "Yes" =~ /.*/; print "$&\n"; }; for $& ("No!") { alarm (1); sleep 2; }

      As far as I'm concerned, anything other than for my $var (LIST) and for $_ (LIST) should be avoided. But it's probably best if enforced by perlcritic rather than warnings.

      Honestly, it's rather obvious that $1 is special. If you start mucking with special vars, you get what you deserve.