Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Monday, March 05, 2012

Warnings, variables, and unnested brackets

I have long been fascinated by improperly nested bracketed constructs, such as [ ( ] ).

Today I ran into an example of a situation that might warrant such improper nesting. I decided to clean up a Perl script, converting it to 'use strict'.  Along the way I enabled warnings using Perl's lexically scoped 'use warnings' facility. In places I had to disable warnings, to make the code compile and run with few enough changes.

And so I encountered:

if( ... ) {
   ...
   my $m = an expression with an ignorable warning;
   ...
}
I want to disable the warning for the smallest possible region, but
if( ... ) {
   ...
   { no warnings 'type';
   my $m = an expression with an ignorable warning;
   }
   ...
}
restricts the scope of both the warning disable (good), but also the variable (nad). Whereas letting the warning be disabled until the end of the enclosing lexical scope
if( ... ) {
   ...
   no warnings 'type';
   my $m = an expression with an ignorable warning;
   ...
}
disables the warning for too large a region. What you want is
if( ... ) {
   ...
   <disable-warnings 'type'>
   <variable-scope 'm'>
   my $m = an expression with an ignorable warning;
   </disable-warnings>
   ...
   </variable-scope>
}

No comments: