Re: exporting Constants
Ah, I see the difference now. I didn't realize that you could still do the export without being an exporter. With that distinction I understand. HI is actually put into the namespace if you are an exporter...if you are not, then HI remains in the THGTest namespace. Thanks for all you help in clarifying the issue. Tanton - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 5:12 PM Subject: Re: exporting Constants > Tanton Gibbs wrote: > > > Sure it is, because you imported it from Test...I tried the following > > No, you can call (or use the constant) it without full qualifying it doens't > mean the function or the constant is in your namespace. as you said below, > Perl has way of finding it from the Exporter interface. the function or > constant still belongs to the package it's defined. when you import > something, it only makes it available for you to use in your script. you > don't need to fully qualify it because you said you are an > Exporter(@ISA=qw(Exporter)). I don't use Exporter so I fully qualify it. > > how about a little experiment? > > #!/usr/bin/perl -w > use strict; > > use THGTest qw(HI); #-- See I learn not to use Test :-) Thanks! > > print "$_: $::{$_}\n" for(keys %::); > > #-- > #-- Now do this: > #-- > print "$_: $THGTest::{$_}\n" for(keys %THGTest::); > > __END__ > > for the first for(...): > see if you can find HI anywhere. You won't find it because it's not there! > You still can use it but it doesn't belong to you. > > for the second for(...): > you will see something like: > HI: *Model::HI > > btw, @ISA=qw(Exporter) is not strictly neccessary but pretty much everyone > agree it's a good thing to do for the reason mentioned above... > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Tanton Gibbs wrote: > Sure it is, because you imported it from Test...I tried the following No, you can call (or use the constant) it without full qualifying it doens't mean the function or the constant is in your namespace. as you said below, Perl has way of finding it from the Exporter interface. the function or constant still belongs to the package it's defined. when you import something, it only makes it available for you to use in your script. you don't need to fully qualify it because you said you are an Exporter(@ISA=qw(Exporter)). I don't use Exporter so I fully qualify it. how about a little experiment? #!/usr/bin/perl -w use strict; use THGTest qw(HI); #-- See I learn not to use Test :-) Thanks! print "$_: $::{$_}\n" for(keys %::); #-- #-- Now do this: #-- print "$_: $THGTest::{$_}\n" for(keys %THGTest::); __END__ for the first for(...): see if you can find HI anywhere. You won't find it because it's not there! You still can use it but it doesn't belong to you. for the second for(...): you will see something like: HI: *Model::HI btw, @ISA=qw(Exporter) is not strictly neccessary but pretty much everyone agree it's a good thing to do for the reason mentioned above... david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
oops, left off a ; and a 1; corrections below. - Original Message - From: "Tanton Gibbs" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 4:44 PM Subject: Re: exporting Constants > Sure it is, because you imported it from Test...I tried the following > example and it worked fine > > #In file THGTest.pm > > package THGTest; > use Exporter; > > our @ISA=qw(Exporter); > our @EXPORT_OK=qw(HI); > > use constant HI => 'Hi, I am a constant.' should be use constant HI => 'Hi, I am a constant.'; 1; > > #in file test.pl > use THGTest qw(HI); > > print HI, "\n"; > > Two notes: > 1.) In your original example, you didn't have the @ISA, which IIRC, is > necessary > 2.) You should never create a Test.pm because perl already comes with > Test.pm > > Tanton > - Original Message ----- > From: "david" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, November 22, 2002 4:13 PM > Subject: Re: exporting Constants > > > > Tanton Gibbs wrote: > > > > > Huh? I thought constants were implemented as functions? In other > words, > > > HI and HI() should both refer to the same entity. > > > > true. but not in the your current namespace. > > > > david > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Sure it is, because you imported it from Test...I tried the following example and it worked fine #In file THGTest.pm package THGTest; use Exporter; our @ISA=qw(Exporter); our @EXPORT_OK=qw(HI); use constant HI => 'Hi, I am a constant.' #in file test.pl use THGTest qw(HI); print HI, "\n"; Two notes: 1.) In your original example, you didn't have the @ISA, which IIRC, is necessary 2.) You should never create a Test.pm because perl already comes with Test.pm Tanton - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 4:13 PM Subject: Re: exporting Constants > Tanton Gibbs wrote: > > > Huh? I thought constants were implemented as functions? In other words, > > HI and HI() should both refer to the same entity. > > true. but not in the your current namespace. > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Tanton Gibbs wrote: > Huh? I thought constants were implemented as functions? In other words, > HI and HI() should both refer to the same entity. true. but not in the your current namespace. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Huh? I thought constants were implemented as functions? In other words, HI and HI() should both refer to the same entity. - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 4:06 PM Subject: Re: exporting Constants > Tanton Gibbs wrote: > > > Ah, then what about > > print HI, "\n"; > > > > no. sorry! :-( > > in that case, Perl probably thinks that you want to call the function HI and > than print whatever that function return to STDOUT. > > no such HI function so Perl will panic! :-) > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Tanton Gibbs wrote: > Ah, then what about > print HI, "\n"; > no. sorry! :-( in that case, Perl probably thinks that you want to call the function HI and than print whatever that function return to STDOUT. no such HI function so Perl will panic! :-) david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Ah, then what about print HI, "\n"; the comma should disambiguate from a filehandle, right? - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 4:02 PM Subject: Re: exporting Constants > Tanton Gibbs wrote: > > > Will print HI; not work...you would think you wouldn't have to qualify it > > if you import it into your namespace? > > the statement: > > print HI; > > won't work. it's: > > print Test::HI,"\n"; > > that i have in the code. Otherwise, Perl thinks that you want to print $_ to > the HI file handle. > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Tanton Gibbs wrote: > Will print HI; not work...you would think you wouldn't have to qualify it > if you import it into your namespace? the statement: print HI; won't work. it's: print Test::HI,"\n"; that i have in the code. Otherwise, Perl thinks that you want to print $_ to the HI file handle. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Will print HI; not work...you would think you wouldn't have to qualify it if you import it into your namespace? - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 22, 2002 3:32 PM Subject: Re: exporting Constants > Tom Allison wrote: > > > How do I export a Constant from a module? > > > > Test.pm: > > > > package Test; > > > > @EXPORT_OK = qw(__what__); > > use constant FOO => 123; > > > > name the following Test.pm: > > #!/usr/bin/perl -w > use strict; > > package Test; > > use Exporter; > our @EXPORT_OK = qw(HI); > > use constant HI => 'Hi I am a constant in Test.pm'; > > 1; > > __END__ > > name the following test.pl: > > #!/usr/bin/perl -w > use strict; > > use Test qw(HI); > > print TEST::HI,"\n"; > > __END__ > > prints: > > Hi I am a constant in Test.pm > > that's what you want right? > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: exporting Constants
Tom Allison wrote: > How do I export a Constant from a module? > > Test.pm: > > package Test; > > @EXPORT_OK = qw(__what__); > use constant FOO => 123; > name the following Test.pm: #!/usr/bin/perl -w use strict; package Test; use Exporter; our @EXPORT_OK = qw(HI); use constant HI => 'Hi I am a constant in Test.pm'; 1; __END__ name the following test.pl: #!/usr/bin/perl -w use strict; use Test qw(HI); print TEST::HI,"\n"; __END__ prints: Hi I am a constant in Test.pm that's what you want right? david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
exporting Constants
How do I export a Constant from a module? Test.pm: package Test; @EXPORT_OK = qw(__what__); use constant FOO => 123; -- In the land of the dark the Ship of the Sun is driven by the Grateful Dead. -- Egyptian Book of the Dead -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]