Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Constant redefined

by Ctrl-z (Friar)
on May 31, 2005 at 12:05 UTC ( [id://462011]=note: print w/replies, xml ) Need Help??


in reply to Constant redefined

Ive done this using davidos closing STDERR approach. Depending on what you really are doing - assuming its not just defining a constant twice - you can minimise the loss of real warnings elsewhere, eg
package Yuk; sub import { 1. close stderr 2. do that thing 3. reopen stderr }



time was, I could move my arms like a bird and...

Replies are listed 'Best First'.
Re^2: Constant redefined
by davido (Cardinal) on May 31, 2005 at 16:10 UTC

    I'm unhappy with the solution I provided above because it seems like a really "Bad Idea" to close STDERR right in the middle of compilation, even if it is only for a little while. Who knows what other messages that is causing to be squelched! And that can make debugging a nightmare.

    So I set out to find another more wholesome solution. It can't really be considered wholesome to tie a filehandle (tied filehandles aren't even yet fully reliable and fully implemented), but its better than sticking ones head in the sand like an ostrich by closing STDERR at such a critical moment.

    So that's exactly my solution; tie STDERR to a class that squelches only messages containing the word "constant". Here it is, and as you can see, it works great.

    use warnings; use strict; BEGIN{ package ConstErr; use Tie::Handle; our @ISA = qw(Tie::Handle); sub TIEHANDLE { bless \my $i, shift; } sub PRINT { my $r = shift; print grep { $_ !~ m/constant/i } @_; } package main; tie *STDERR, 'ConstErr'; } use constant PI => 3.14; print PI, "\n"; use constant PI => 1000; print PI, "\n";

    Again, let me reiterate that I still consider the whole idea to be a bad one, but if the purpose of this discussion is purely academic, and only seeking to find solutions to a theoretical problem, this is the best solution I can think of.


    Dave

      But isn't this conceptually incorrect? why would someone want to modify a constant? if it was to be modified then why is it declared as a constant in the first place?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://462011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found