Scope of variables in a function

Dirk Koopman djk at tobit.co.uk
Sat Jun 1 18:23:29 BST 2013


On 01/06/13 18:03, Hakim Cassimally wrote:
> Andy,
>
> I believe your problem is:
>
>      my $x = 'FOO' if $condition;
>
> This only declares the new variable if $condition, so it ends up having
> surprising, static-like behaviour, which you probably shouldn't rely on.
>
> Rewriting to:
>
>     my $result;
>     $result = 'FOO' if ...
>
> gives your expected result.


It is very annoying. The more so because this is an artefact that is 
(apparently) relied on by a lot of legacy code.

Quite a lot of other perl artefacts have been deprecated and then 
removed. Why does this one persist? In what way is it useful or intuitive?



More information about the london.pm mailing list