Because you're declaring the wanted sub inside an enclosing block containing lexical (my) variables, those variables create closures, and when the sub uses these variables, it gets the copies that were in existence when it was first compiled. The next time through the loop, a new variable is created, and the variable in the sub and outside it no longer refer to the same thing.
The easiest fix is to not use lexical variables. Declare $currentstoryid and $exists with our instead of my, and the problem goes away. Another solution is to create a new anonymous sub for each call to find:
my $currentstoryid = $entry; my $exists=0; &find( sub { if (/$currentstoryid/) { $exists = 1; return $exists; } }, $sitedir);
In reply to Re: file::find subroutine not getting new values
by sgifford
in thread file::find subroutine not getting new values
by ilovechristy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |