develooper Front page | perl.perl6.language | Postings from April 2005

turning off warnings for a function's params?

Thread Next
From:
David Storrs
Date:
April 24, 2005 19:50
Subject:
turning off warnings for a function's params?
Message ID:
20050425025001.GA48670@megazone.bigpanda.com
I image we've all written logging code that looks something like this
(Perl5 syntax):

  sub foo {
      my ($x,$y) = @_;
      note("Entering frobnitz().  params: '$x', '$y'"); 
      ...
  }

This, of course, throws an 'uninitialized value in concatenation or
string' warning when your test suite does this:

  is( foo(undef, undef), undef, "foo(undef, undef) gives undef" );

In a testing environment, I don't want to see this warning.  In a
production environment, I do.  Furthermore, when I want it gone, I
want it gone from every instance of C<note>, without having to change
something in every location.  I suppose I could change all my logging
calls to look like this:

  {
    if ( $DEBUG ) { no warnings 'uninitialized'; note("...."); }
    else { note("...."); }
  }

But that's really ugly, takes up a lot of space, is confusing, and is
redundant.

How would I best solve this problem in Perl6?

--Dks


-- 
dstorrs@dstorrs.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About