Thank you for your answer.

Yes, I thought so too. Constants are by definition not-variables. I wanted 
to know this for the following reasons:

1. All you know how a company asks you to change the less code possible 
whenever something is requested in critical applications.
2. I didn't desing the modules. The person who did it thought that using 
constants would be nice and he didn't think about something like this 
coming.
3. This module is superclass for other 15 modules that use its constants.

So, I will have to modify such constants in all 16 modules to convert them 
in variables in order to make them configurable. I guess It's always better 
a clean long fix than a dirty short patch. :-)

Thank you again.

Cheers,

Paco Zarabozo





From: Brian Raven
Sent: Wednesday, March 05, 2008 8:10 AM
To: [email protected]
Subject: RE: Redefining Constants


Zarabozo, Francisco (GE, Corporate) <> wrote:
> Hello All,
>
> I'm having some trouble with a module where I need to implement a
> change.
> Basically, this module defines constants that other modules will use
> at a later time.
>
> I need to detect parameters in the import() sub (that's the requested
> change) and, if the case, redefine some of those constants.
>
> I'm trying with evals but all I'm getting is a warning about
> "constant redefined", AND the constant is not really changing (it
> keeps its previous value).

No. It will be complaining about a subroutine being redefined.

>
> Is there a way to correctly redefine a constant at import() time?

I would hope not! That would subvert the whole concept of a constant.
However, ...

>
> Here is a simple example of the scene:
>
> Script.pl
> -----------------
> use strict;
> use warnings;
> use myModule constantA => 'foo';
> -----------------
>
> myModule.pm
> -----------------
> package myModule;
> use strict;
> use warnings;
> use constant constantA => 'bar';
>
> sub import {
>     my %params = @_;
>     if ($params{constantA}) {
>         # This should change constantA from 'bar' to 'foo'
>         eval 'use constant constantA => \''.$params{constantA}.'\'';
>         warn $@ if $@;
>     }
> }
> -----------------
>
> Any comments are highly appreciated.

While this appears to do what you want (at least it does after
modification), the warning about redefinition of a subroutine may be
hard to inhibit without changing constant.pm. One way would be to avoid
redefining any subroutines, e.g.

------------------------
use strict;
use warnings;
package myModule;

our %defaults = (constantA => 'bar');

sub import {
    my $module = shift;
    my %params = @_;
    foreach my $k (keys %defaults) {
my $val = defined($params{$k}) ? $params{$k} : $defaults{$k};
eval qq{use constant $k => '$val'};
warn $@ if $@;
    }
}

1;
--------------------------

Its not entirely clear what you are trying to achieve, but I don't think
that variable constants (i.e. constants that are not constant) is a good
way to do it.

HTH

-- 
Brian Raven


=========================================
Atos Euronext Market Solutions Disclaimer
=========================================

The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender 
immediately and delete it from your system. The views expressed in this 
message do not necessarily reflect those of Atos Euronext Market Solutions.

Atos Euronext Market Solutions Limited - Registered in England & Wales with 
registration no. 3962327.  Registered office address at 25 Bank Street 
London E14 5NQ United Kingdom.
Atos Euronext Market Solutions SAS - Registered in France with registration 
no. 425 100 294.  Registered office address at 6/8 Boulevard Haussmann 75009 
Paris France.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet 
e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de 
votre systeme. Le contenu de ce message electronique ne represente pas 
necessairement la position ou le point de vue d'Atos Euronext Market 
Solutions.
Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée 
au Royaume Uni sous le numéro 3962327, dont le siège social se situe 25 Bank 
Street E14 5NQ Londres Royaume Uni.

Atos Euronext Market Solutions SAS, société par actions simplifiée, 
enregistré au registre dui commerce et des sociétés sous le numéro 425 100 
294 RCS Paris et dont le siège social se situe 6/8 Boulevard Haussmann 75009 
Paris France.
=========================================

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs 

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to