Drieux wrote: > > On Wednesday, Nov 19, 2003, at 06:38 US/Pacific, Haim Ashkenazi wrote: > >> Hi >> >> I'm writing a module to serve a script I'm writing and I was wondering >> if >> it's possible to add a constant to the @EXPORT array. I prefer not to >> use >> variables because these settings shouldn't be changed, but I want every >> script that uses this module to be able to access these constants. >> >> I read somewhere that you can declare your constants like this: >> *BLAH = \"blah blah"; >> and then export $BLAH. >> >> I tested it and it works, but I wanted to know if that's a good way of >> doing >> it, or there's a better one in terms of speed and memory usage. > > well first off do you mean > > use constant MY_CONSTANT => 82 ; # capitalizing them can help ID them. > > { cf. perldoc constant } > > which is how I put them into a production perl module. > > Then think in terms of whether you want to have them > always exported, eg @EXPORT, or can you 'bundle' them > in %EXPORT_TAGS eg: > > our %EXPORT_TAGS = ( 'all' => [ qw( .... ) ], > 'constants' => [ qw(....) ], > .... > ); > > This way if some of the constants natively cluster with > some of the functions, then you can think in terms of > and code the 'traditional' form of > > bail_out($thing,$poo,$err_num) > if( my_got_error($that_return) == MY_CONSTANT ); > > which while 'traumatizing' some of the "c-coders" could > be 'repositioned' for them as > > if( my_got_error($that_return) == MY_CONSTANT ) { > bail_out($thing,$poo,$err_num); > } > > Is that the sort of idea that you are looking at? > or would the 'accessor' method be more interesting? > > sub get_my_constant { MY_CONSTANT ; } > > so that you could have > > if ( $obj->my_got_error($that_return) == $obj->get_my_constant() ) { > bail_out($thing,$poo,$err_num); > } I was talking about the first example, but I think I've made a mistake... I tried to add the constant to to my @EXPORT (which was declared with "use constant ...") and I've got an error. I was probably too quick to assume it can't be done that way, instead of trying to figure out the error... I tried it again now and it works.
so, thanks Bye -- Haim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]