http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11998
--- Comment #32 from Robin Sheat <[email protected]> --- (In reply to Jonathan Druart from comment #30) > Created attachment 33183 [details] [review] > Bug 11998: QA follow-up - fix the perlcritic error > > % perlcritic C4/Context.pm > Variable declared in conditional statement at line 544, column 5. > Declare variables outside of the condition. (Severity: 5) So I was wondering what purpose this change solves, turns out it can be important: <grantm> my $var if condition is a messy construct that doesn't do quite what you expect <grantm> if condition is true, then $var is created in the current scope and gets cleaned up when the scope ends <grantm> but if condition is not true, then $var does not get created at runtime and instead, the $var that was inferred at compile time is used instead <grantm> it ends up being a file-scoped global that persists a value <Ned> ahh <Ned> that's a bit of a nasty side-effect :p <grantm> actually, it's not a file-scoped global <grantm> it's a lexical and the sub is a closure over that lexical <grantm> the thing about 'my' is that it has compile-time and run-time effects and in this instance the run-time effects only get to happen if condition is true <grantm> historical note: this bug/feature was how people used to do state variables before the 'state' keyword existed <Ned> heh <grantm> specifically: my $state_variable = 0 if 0; <Ned> there should be a word for that <Ned> "fug" perhaps <grantm> it's certainly fugly -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
