in reply to Why the variable $n was undef?

my ... for ...; and my ... if ...; are not valid constructs. The results are undefined. The first doesn't even make any sense.