APM: Dumb program acting funny...

Bill Raty bill.raty at gmail.com
Thu Oct 19 04:27:38 PDT 2006


I've ceased using "no strict 'refs'", and instead use the excellent Symbol
module to manipulate the symbol table.

Instead of:

use strict;
{
  no strict 'refs';
  my ($pkg, $subname) = qw( Foo bar );
  *{"${pkg}::${subname}"} = sub { print "Howdy!\n" };
}

I use:

use strict;
use Symbol;
my ($pkg, $subname) = qw( Foo bar );
*{Symbol::qualify_to_ref( $subname, $pkg )} = sub { print "Howdy!\n" };

On 10/19/06, Mike Stok <mike at stok.co.uk> wrote:
>
>
> On 19-Oct-06, at 1:14 AM, Bill Raty wrote:
>
> You have warnings enabled 'the -w switch on shebang'.
>
> With warnings enabled perl will output a message whenever it detects an
> undefined value in a join or string interpolation.  To demonstrate:
>
>   use warnings;
>   use strict;
>
>   my $empty = undef;
>   print "Perl will warn about this $empty string.\n";
>
> I rarely use warnings in production code.  It is better to locally scope
> warnings in code sections where you are certain you must always have data
> that is not null.
>
>
> I usually work the other way around, using warnings everywhere, and then
> using no warnings as tightly scoped as possible to mark where I know
> uninitialized variables and perl's treatment of them are OK
>
> use strict;
> use warnings;
>
> my $empty = undef;
> {
>     no warnings 'uninitialized';
>     print "Perl will not warn about this $empty string.\n";
> }
>
> (Let's not notice that $empty is initialized in this code, so the warning
> is misleading.)
>
> The same goes for using "no strict 'refs';"  around code where I might be
> using strings to manipulate the symbol table.
>
> The lexical relaxation reminds me later that I was doing something "odd"
> in this chunk of code.
>
>
> Mike
>
> --
>
> Mike Stok <mike at stok.co.uk>
> http://www.stok.ca/~mike/ <http://www.stok.ca/%7Emike/>
>
> The "`Stok' disclaimers" apply.
>
>
>
>
>


-- 
For a list of all the ways technology has failed to improve the quality of
life, please press three.
  - Alice Kahn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/austin/attachments/20061019/002ef6fa/attachment.html 


More information about the Austin mailing list