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

Re: [PBML] question about scope

Expand Messages
  • Jenda Krynicky
    From: Jeff japhy Pinyan ... And more importantly the sympols imported by them are not visible just in the scope of the current procedure
    Message 1 of 3 , Aug 31, 2004
    • 0 Attachment
      From: Jeff 'japhy' Pinyan <japhy@...>
      > On Aug 31, greg.hering@... said:
      >
      > >I have recently begun sticking my 'use <module>' statements after the
      > >'sub <function_name>'
      >
      > That might be a helpful visual aid, but it does not achieve the effect
      > you think it does.
      >
      > >sub print_msg {
      > > use POSIX qw(strftime);
      > > my $msg = @_ > 0 ? shift(@_) : "no message";
      > >
      > > my $datestring = strftime "%Y-%m-%d %H:%M:%S\n", localtime;
      > >
      > > chomp( $datestring );
      > > printf( "%s %s", $datestring, $msg );
      > >}
      > >
      > >It sort of 'localizes' them to the function they are used in, but I
      > >haven't seen this in other people's code and wondered if it was bad
      > >practice.
      >
      > 'use' statements happen at compile-time, not run-time.

      And more importantly the sympols imported by them are not visible
      just in the scope of the current procedure but in the whole file. Or
      I should rather say, the symbols are imported into the current
      package, not the current block.

      On the other hand it does make a lot of sense to use some pragmas
      like this. Eg. 'use strict' and 'no strict', 'use warnings' and 'no
      warnings' ...

      ('no' is just a special form of use. It loads the module if necessary
      just as the 'use' would do, but then call the module's method
      unimport() instead of import().)

      Jenda
      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery
    Your message has been successfully submitted and would be delivered to recipients shortly.