use constant still misbehaving?

use constant still misbehaving?

am 01.02.2007 16:53:44 von Deane.Rothenmaier

This is a multipart message in MIME format.
--===============1913170000==
Content-Type: multipart/alternative;
boundary="=_alternative 00575CFF06257275_="

This is a multipart message in MIME format.
--=_alternative 00575CFF06257275_=
Content-Type: text/plain; charset="us-ascii"

Seems there's more going wrong here. Sample code:

use constant ( # note parens, not curlies
CONT => 0,
EXIT => 1,
);

sub use_it {
my ($code, $msg) = @_;

print "code = $code, message = \"$msg\"\n";

}

# now try the sub call:
use_it( CONT, "hello world" );

------------------------------------------------------------ --------------------

output:

code = 0, message = "EXIT"

If I replace the parens in the use constant line with curlies, it works
when interpreted and dies when compiled as in my OP. The output here is
also from a compiled executable. I've given up on using the constants, but
would appreciate any insights as to just what the heck went wrong...

Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150

"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 00575CFF06257275_=
Content-Type: text/html; charset="us-ascii"



Seems there's more going wrong here. Sample code:



use constant (                  # note parens, not curlies

    CONT => 0,

    EXIT => 1,

);



sub use_it {

my ($code, $msg) = @_;



   print "code = $code, message = \"$msg\"\n";



}



# now try the sub call:

use_it( CONT, "hello world" );



------------------------------------------------------------ --------------------



output:



code = 0, message = "EXIT"



If I replace the parens in the use constant line with curlies, it works when interpreted and dies when compiled as in my OP. The output here is also from a compiled executable. I've given up on using the constants, but would appreciate any insights as to just what the heck went wrong...



Deane Rothenmaier

Systems Architect

Walgreens Corp.

847-914-5150



"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage

--=_alternative 00575CFF06257275_=--


--===============1913170000==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1913170000==--

Re: use constant still misbehaving?

am 01.02.2007 17:05:06 von Jan Dubois

On Thu, 1 Feb 2007 09:53:44 -0600, Deane.Rothenmaier@walgreens.com
wrote:

>Seems there's more going wrong here. Sample code:
>
>use constant ( # note parens, not curlies

Your comment points out the problem: you *should* use curlies in your
sample. Your code as written is the same as:

use constant CONT => (0, 'EXIT', 1);

It defines CONT as a list, not as a scalar.

Cheers,
-Jan


> CONT => 0,
> EXIT => 1,
>);
>
>sub use_it {
>my ($code, $msg) = @_;
>
> print "code = $code, message = \"$msg\"\n";
>
>}
>
># now try the sub call:
>use_it( CONT, "hello world" );
>
>----------------------------------------------------------- ---------------------
>
>output:
>
>code = 0, message = "EXIT"
>
>If I replace the parens in the use constant line with curlies, it works
>when interpreted and dies when compiled as in my OP. The output here is
>also from a compiled executable. I've given up on using the constants, but
>would appreciate any insights as to just what the heck went wrong...
>
>Deane Rothenmaier
>Systems Architect
>Walgreens Corp.
>847-914-5150
>
>"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
>Babbage, if you put into the machine wrong figures, will the right answers
>come out?' I am not able rightly to apprehend the kind of confusion of
>ideas that could provoke such a question." -- Charles Babbage

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: use constant still misbehaving?

am 01.02.2007 17:34:15 von Brian Raven

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Deane.Rothenmaier@walgreens.com
Sent: 01 February 2007 15:54
To: activeperl@listserv.ActiveState.com
Subject: use constant still misbehaving?

> Seems there's more going wrong here. Sample code:
>
> use constant ( # note parens, not curlies
> CONT => 0,
> EXIT => 1,
> );
>
> sub use_it {
> my ($code, $msg) = @_;
>
> print "code = $code, message = \"$msg\"\n";
>
> }

> # now try the sub call:
> use_it( CONT, "hello world" );
>
>
------------------------------------------------------------ ------------
--------
>
> output:
>
> code = 0, message = "EXIT"
>
> If I replace the parens in the use constant line with curlies, it
works when interpreted and dies when compiled > as in my OP. The output
here is also from a compiled executable. I've given up on using the
constants, but
> would appreciate any insights as to just what the heck went wrong...

No. You must use curly brackets to define multiple constants.

I think your problem is probably a 'feature' of PerlApp. I tried your
example with pp and it seemed OK.

Also, consider defining constants one at a time. PerlApp may be happier
with that.

HTH

--
Brian Raven

_________________________________________

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 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.

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.

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: use constant still misbehaving?

am 02.02.2007 05:02:13 von Foo JH

Not directly relating to the problem at hand, but you may want to
consider using the Readonly library instead. It locks the variable from
changes in the value, but has some advantages over the constant
counterpart.

Deane.Rothenmaier@walgreens.com wrote:
>
> Seems there's more going wrong here. Sample code:
>
> use constant ( # note parens, not curlies
> CONT => 0,
> EXIT => 1,
> );
>
> sub use_it {
> my ($code, $msg) = @_;
>
> print "code = $code, message = \"$msg\"\n";
>
> }
>
> # now try the sub call:
> use_it( CONT, "hello world" );
>
> ------------------------------------------------------------ --------------------
>
>
> output:
>
> code = 0, message = "EXIT"
>
> If I replace the parens in the use constant line with curlies, it
> works when interpreted and dies when compiled as in my OP. The output
> here is also from a compiled executable. I've given up on using the
> constants, but would appreciate any insights as to just what the heck
> went wrong...
>
> Deane Rothenmaier
> Systems Architect
> Walgreens Corp.
> 847-914-5150
>
> "On two occasions I have been asked [by members of Parliament], 'Pray,
> Mr. Babbage, if you put into the machine wrong figures, will the right
> answers come out?' I am not able rightly to apprehend the kind of
> confusion of ideas that could provoke such a question." -- Charles
> Babbage
> ------------------------------------------------------------ ------------
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs