in reply to Odd lexical variable behavior -- why does this happen?

Dumping the reference with Devel::Peek inside your sub count_up
sub count_up { $mw->update; my $progress = 0; warn "after \$progress init($counter):\n"; Dump($progress); $pb->configure( -from => 0, -to => 20, -variable => \$progress, ## store the reference. ); my $cnt = 0; print "\$cnt=$cnt; \$progress=$progress\n"; for (1) { $progress++; warn "\$progreess in for() loop($counter):\n"; Dump($progress); $cnt++ unless ($_ % 2); $mw->update; } $counter++; $mw->update; }

reveals

after $progress init(0): SV = IV(0x8e2a5c8) at 0x8de8ce8 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 0 $cnt=0; $progress=0 $progreess in for() loop(0): SV = PVMG(0x8e74828) at 0x8de8ce8 REFCNT = 8 FLAGS = (PADBUSY,PADMY,GMG,SMG,RMG,pIOK) IV = 1 NV = 0 PV = 0x8eb73d8 "0"\0 CUR = 1 LEN = 4 MAGIC = 0x8eb67d8 MG_VIRTUAL = &PL_vtbl_packelem MG_TYPE = PERL_MAGIC_tiedscalar(q) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x8eb4780 SV = RV(0x8b5ffa0) at 0x8eb4780 REFCNT = 1 FLAGS = (ROK) RV = 0x8eb484c SV = PVHV(0x8d7a4c8) at 0x8eb484c REFCNT = 2 FLAGS = (OBJECT,SHAREKEYS) IV = 7 NV = 0 STASH = 0x8dd4694 "Tie::Watch::Scalar" ARRAY = 0x8eb6790 (0:3, 1:3, 2:2) hash quality = 111.4% KEYS = 7 FILL = 5 MAX = 7 RITER = -1 EITER = 0x0 Elt "-shadow" HASH = 0x54c7bc48 SV = IV(0x8e2a4c4) at 0x8eb4858 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 Elt "-destroy" HASH = 0x467b93a1 SV = RV(0x8b5ff94) at 0x8eb4864 REFCNT = 1 FLAGS = (ROK) RV = 0x8e7d448 SV = PVAV(0x8ead8c4) at 0x8e7d448 REFCNT = 1 FLAGS = () IV = 0 NV = 0 ARRAY = 0x8eb4560 FILL = 1 MAX = 1 ARYLEN = 0x0 FLAGS = (REAL) after $progress init(1): SV = IV(0x8e2a4d0) at 0x8e592f0 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 0 $cnt=0; $progress=1 $progreess in for() loop(1): SV = PVMG(0x8eb5778) at 0x8e592f0 REFCNT = 8 FLAGS = (PADBUSY,PADMY,GMG,SMG,RMG,pIOK) IV = 2 NV = 0 PV = 0x8eb74f0 "1"\0 CUR = 1 LEN = 4 MAGIC = 0x8eb6a98 MG_VIRTUAL = &PL_vtbl_packelem MG_TYPE = PERL_MAGIC_tiedscalar(q) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x8eb4a8c SV = RV(0x8b5ffd8) at 0x8eb4a8c REFCNT = 1 FLAGS = (ROK) RV = 0x8eb4b58 SV = PVHV(0x8d7a4f8) at 0x8eb4b58 REFCNT = 2 FLAGS = (OBJECT,SHAREKEYS) IV = 7 NV = 0 STASH = 0x8dd4694 "Tie::Watch::Scalar" ARRAY = 0x8eb8e88 (0:3, 1:3, 2:2) hash quality = 111.4% KEYS = 7 FILL = 5 MAX = 7 RITER = -1 EITER = 0x0 Elt "-shadow" HASH = 0x54c7bc48 SV = IV(0x8e2a5d8) at 0x8eb4b64 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 Elt "-destroy" HASH = 0x467b93a1 SV = RV(0x8b5ffcc) at 0x8eb4b70 REFCNT = 1 FLAGS = (ROK) RV = 0x8e593a4 SV = PVAV(0x8ead814) at 0x8e593a4 REFCNT = 1 FLAGS = () IV = 0 NV = 0 ARRAY = 0x8eb68b0 FILL = 1 MAX = 1 ARYLEN = 0x0 FLAGS = (REAL)
that the Progressbar object remembers the value from the previous configured reference via Tie::Watch voodoo, and you can't reset that value by just passing another reference to configure.

How cool is that? You can't stop progress :-)

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}