develooper Front page | perl.perl5.porters | Postings from March 2006

useless localization of substr?

March 19, 2006 08:40
useless localization of substr?
Message ID:
Blead has a raft of new warnings such as "useless localization of substr",
but the warning and associated diagnostic text are misleading about the
current behaviour. Witness:

zen% perl -wle 'our $a = "ab"; { local substr($a,0,1) = "c"; print "<$a>"; } print "<$a>"'
Useless localization of substr at -e line 1.
Use of uninitialized value $a in substr at -e line 1.

.. which shows (I think) that rather than the local having no effect it
is actually doing:
  { local $a; substr($a, 0, 1) = "c"; ... }

.. and that interpretation is also hinted at by the fatal "Can't localize
lexical variable" if you s/our/my/.

The diagnostics text says:
  [...] but in fact the local() currently has no effect. [...]

This behaviour appears to predate the addition of the warning.

It isn't clear to me what the ideal behaviour would be before we can
support what is actually being asked for, but the current behaviour
seems decidedly counterintuitive - I'm inclined to suggest that die()
would be a more correct response.

(The patch for the warning was introduced in
and applied as change #19588.)

Hugo Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About