in reply to Subroutines within if statements

"a" is always true, so your code always calls addlinks().