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.
Subject Author Views Date
Thread Interesting anomaly - Globals EZFrag 2494 Feb 5, 2010, 3:40 AM
Thread Re: [EZFrag] Interesting anomaly - Globals
Andy 2430 Feb 5, 2010, 5:09 AM
Thread Re: [Andy] Interesting anomaly - Globals
EZFrag 2382 Feb 15, 2010, 12:20 AM
Post Re: [EZFrag] Interesting anomaly - Globals
Andy 2368 Feb 15, 2010, 12:35 AM
Post Re: [EZFrag] Interesting anomaly - Globals
brewt 2348 Feb 15, 2010, 1:44 AM