Why set the length of the array only to change it immediately?
It was one way to do it. The goal was to keep @path with only "pure" node information, and not have redundancies like ".", "/", and previous nodes repeated as the indexes go higher.
I also hate the needless use of global vars.
Me too. But a data structure outside the loop was needed to oversee things.