Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Interesting anomaly - Globals

Quote Reply
Interesting anomaly - Globals
Hi there,

The last couple of months I have developed a top secret system using GLinks. I have just found something interesting, regarding globals. It might help some-one some day.

Lets say I have a global which has another function in it. I'll call it "get_all_links":

Code:

sub {

#code here
my @cats = getSubCats();

sub getSubcats {

#code here

}
}

Now we need an additional similar function. I'll call it "get_back_links":


Code:

sub {

#code here
my @cats = getSubCats();

sub getSubcats {

#the code here is different from that of "get_all_links"

}
}

If I use the global "get_back_links" it will not work properly. It kept me going for two hours before it struck me.
The globals seem to be loaded alphabeticaly. It means that "get_all_links" will be loaded before "get_back_links".
Inside "get_all_links" the function "getSubcats" is already created. So when you call "getSubcats" inside "get_back_links", it won't execute the function "getSubcats" inside "get_back_links", but rather the one inside of "get_all_links".

Is this making sense to anyone?




PS: I fixed it by changing the name of "getSubcats" inside "get_back_links" to something else.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Interesting anomaly - Globals In reply to
Hi,

The other option I do, is to have the functions inside it... ie:

Code:
sub {

do_test();

sub do_test {
do something
}

}

Didn't actually realise you could call the globals from inside each other (never worked for me, but maybe was due to this issue you had)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Interesting anomaly - Globals In reply to
Well, just a though... If this kind of mix up can happen with functions, can it also happen with variables? If it can, I would sigh with relief.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Interesting anomaly - Globals In reply to
Not sure to be honest - maybe someone at GT could shed some light Whistle

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [EZFrag] Interesting anomaly - Globals In reply to
sub {} type globals get loaded by using eval() on them. Your snippet of code isn't something you should do, as it puts that function you defined into into (I'm guessing) GT::Config's namespace. Whichever one that gets called last will redefine that subroutine.

Instead, you should be using a code reference:

Code:
sub {
my $get_sub_cats = sub {
# ...
}

my @cats = $get_sub_cats();
}

Adrian