http://www.perlmonks.org?node_id=892942


in reply to Re: My questions: new to perl
in thread My questions: new to perl

local temporarily saves a package variable. The previous value of the variable will be restored when the current scoped is exited.
That's an incomplete answer. local can localized elements of lexical arrays (and hashes) as well.
my @foo; sub hello {say "@foo";} @foo = qw[Hello, world!]; hello; { local $foo[1] = "earth!"; hello; } __END__ Hello, world! Hello, earth!
strict detects errors that aren't detected by default for backwards compatibility reasons.
That's the first time I hear someone claim strict has anything to do with backwards compatibility reasons. If that were true, no code written in the past 15 years would have had the need for "no strict".
use warnings; detects lots of situations which are very likely to have resulted from errors.
But on other cases, it's just plain wrong - specially in cases where a linter would have been more appropriate. For instance, the code I posted above isn't warnings free (but what is warned about should be done by a linter, not by warnings, IMO).

Replies are listed 'Best First'.
Re^3: My questions: new to perl
by ikegami (Patriarch) on Mar 13, 2011 at 18:27 UTC

    That's an incomplete answer. local can localized elements of lexical arrays (and hashes) as well.

    Thanks, added.

    That's the first time I hear someone claim strict has anything to do with backwards compatibility reasons. If that were true, no code written in the past 15 years would have had the need for "no strict"

    You didn't finish your thought. Are you saying you disagree with the conclusion? How so?

    By the way, strict is now on by default in Perl 5.12 (the language, not the interpreter).*

    But on other cases, it's just plain wrong [...] For instance, the code I posted above isn't warnings free

    Comma in qw() is most definitely likely to be an error. I for one have taken advantage of this warning a couple of times.

    * — To use Perl 5.12, add use 5.012;.

    Update: Added "*".

      Are you saying you disagree with the conclusion?
      Most certainly.

      strict has been around as long as perl5. Which is as long as we have namespaces, and Exporter. Exporter only works by doing things strict forbids - but which weren't even possible before. So, strict forbids something that has only been possible for as long as strict exists. Not really "for backwards compatible reasons".

      By the way, strict is now on by default in Perl 5.12
      Except that it's not.
      print $], "\n"; $foo = 3; print $foo, "\n"; __END__ 5.012001 3
      Perhaps you mean that use 5.012; implies use strict;?
      Comma in qw() is most definitely likely to be an error.
      They are seldomly an error in my code (for instance, in the code shown), and nor are #'s in my qw's.
      I for one have taken advantage of this warning a couple of times.
      That I will not deny. But since the presence of commas can be detected without running the program, I do not think checking for this at every run is required. This is something that belongs in a linter. Perlcritic is a linter, and works wonders for tons of people.

        By the way, strict is now on by default in Perl 5.12

        Except that it's not.

        Did you deliberately misquote me? I specifically said version 5.12 of the interpreter wasn't sufficient.

        Since 5.10, Perl has been changing in backwards incompatible ways. To get the latest version of the language, you need to request it using use 5.010; or similar.

        But since the presence of commas can be detected without running the program, I do not think checking for this at every run is required.

        Either you didn't express yourself properly, or you just advocated that strict var checks be moved to the linter.