Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] (my vs our) && warnings

Expand Messages
  • Mike Dillinger
    ... This works better for me. For Windows and UNIX/Linux, call your script using the -w option. So for instance, perl -w or #!/path/to/perl
    Message 1 of 5 , Feb 8, 2005
    • 0 Attachment
      Message from "Paul Archer" on 02/08/05 01:28 PM PT quoted:
      > I was playing around with a script the other day when I noticed that
      > despite the fact that I had warnings turned on, I wasn't getting a warning
      > that I had used a variable only once. (Using a variable only once is, of
      > course, an indicator that you have a typo.) Then I noticed that I had scoped
      > the variable with 'my'. I replaced 'my' with 'our' (which doesn't lexically
      > scope the variable, but satisfies the 'strict' pragma). I then got an error.
      >
      > So, the question is: how do I 'use warnings' && use my && get notified about
      > variables I'm only using once?
      >
      > Paul

      This works better for me.

      For Windows and UNIX/Linux, call your script using the "-w" option. So
      for instance, "perl -w <scriptname>" or "#!/path/to/perl -w" at the top.

      -MikeD
    • Stevo
      ... use strict; http://www.newbie.org/snippets/cgi/content/general10.html
      Message 2 of 5 , Feb 8, 2005
      • 0 Attachment
        On Tue, 8 Feb 2005 15:28:11 -0600 (CST), Paul Archer <tigger@...> wrote:
        > I was playing around with a script the other day when I noticed that
        > despite the fact that I had warnings turned on, I wasn't getting a warning
        > that I had used a variable only once. (Using a variable only once is, of
        > course, an indicator that you have a typo.) Then I noticed that I had
        > scoped
        > the variable with 'my'. I replaced 'my' with 'our' (which doesn't lexically
        > scope the variable, but satisfies the 'strict' pragma). I then got an
        > error.
        >
        > So, the question is: how do I 'use warnings' && use my && get notified
        > about
        > variables I'm only using once?
        >
        > Paul

        use strict;

        http://www.newbie.org/snippets/cgi/content/general10.html
      • Paul Archer
        ... If I weren t using strict, do you think I d be worried about delcaring my variables? shebop:~ # cat /tmp/warning-strict.pl #!/usr/bin/perl use strict; use
        Message 3 of 5 , Feb 8, 2005
        • 0 Attachment
          5:46pm, Stevo wrote:

          >
          > On Tue, 8 Feb 2005 15:28:11 -0600 (CST), Paul Archer <tigger@...> wrote:
          >> I was playing around with a script the other day when I noticed that
          >> despite the fact that I had warnings turned on, I wasn't getting a warning
          >> that I had used a variable only once. (Using a variable only once is, of
          >> course, an indicator that you have a typo.) Then I noticed that I had
          >> scoped
          >> the variable with 'my'. I replaced 'my' with 'our' (which doesn't lexically
          >> scope the variable, but satisfies the 'strict' pragma). I then got an
          >> error.
          >>
          >> So, the question is: how do I 'use warnings' && use my && get notified
          >> about
          >> variables I'm only using once?
          >>
          >> Paul
          >
          > use strict;
          >
          > http://www.newbie.org/snippets/cgi/content/general10.html
          >
          If I weren't using strict, do you think I'd be worried about delcaring my
          variables?

          shebop:~ # cat /tmp/warning-strict.pl
          #!/usr/bin/perl
          use strict;
          use warnings;

          my $my_variable_used_only_once=1;
          our $our_variable_used_only_once=1;
          $main::global_variable_used_only_once=1;
          print "the script is running\n";
          shebop:~ # perl -v

          This is perl, v5.8.3 built for i586-linux-thread-multi
          [...etc...]

          shebop:~ # /tmp/warning-strict.pl
          Name "main::global_variable_used_only_once" used only once: possible typo at
          /tmp/warning-strict.pl line 7.
          the script is running
          shebop:~ #
        • daymobrew@yahoo.com
          ... a warning ... once is, of ... I had ... doesn t lexically ... got an ... notified ... delcaring my ... typo at ... Hack idea: sed s/my /our /
          Message 4 of 5 , Feb 9, 2005
          • 0 Attachment
            --- In perl-beginner@yahoogroups.com, Paul Archer <tigger@i...> wrote:
            > 5:46pm, Stevo wrote:
            >
            > >
            > > On Tue, 8 Feb 2005 15:28:11 -0600 (CST), Paul Archer <tigger@i...>
            wrote:
            > >> I was playing around with a script the other day when I noticed that
            > >> despite the fact that I had warnings turned on, I wasn't getting
            a warning
            > >> that I had used a variable only once. (Using a variable only
            once is, of
            > >> course, an indicator that you have a typo.) Then I noticed that
            I had
            > >> scoped
            > >> the variable with 'my'. I replaced 'my' with 'our' (which
            doesn't lexically
            > >> scope the variable, but satisfies the 'strict' pragma). I then
            got an
            > >> error.
            > >>
            > >> So, the question is: how do I 'use warnings' && use my && get
            notified
            > >> about
            > >> variables I'm only using once?
            > >>
            > >> Paul
            > >
            > > use strict;
            > >
            > > http://www.newbie.org/snippets/cgi/content/general10.html
            > >
            > If I weren't using strict, do you think I'd be worried about
            delcaring my
            > variables?
            >
            > shebop:~ # cat /tmp/warning-strict.pl
            > #!/usr/bin/perl
            > use strict;
            > use warnings;
            >
            > my $my_variable_used_only_once=1;
            > our $our_variable_used_only_once=1;
            > $main::global_variable_used_only_once=1;
            > print "the script is running\n";
            > shebop:~ # perl -v
            >
            > This is perl, v5.8.3 built for i586-linux-thread-multi
            > [...etc...]
            >
            > shebop:~ # /tmp/warning-strict.pl
            > Name "main::global_variable_used_only_once" used only once: possible
            typo at
            > /tmp/warning-strict.pl line 7.
            > the script is running
            > shebop:~ #

            Hack idea: sed 's/my /our /' warning_scrict.pl >ws.pl; perl -wc ws.pl

            Ugly, I know but it did report '$my_variable_used_only_once'.
            I too would like this functionality.
          Your message has been successfully submitted and would be delivered to recipients shortly.