http://www.perlmonks.org?node_id=1008924


in reply to looping logic error while printing output from folder/flie content

"..but problem is everytime it prints first filename and it's folder/basefolder name.."

Reason: Because, the first filename "$filenames[0]" is "hardcore" written in your script i.e &write_output subroutine.
see this

... <connection type="PuTTY" name="$filenames[0]"> <connection_info><name>$filenames[0]</name> ...
The filename is not changing. Likewise are other variables used in your &write_output subroutine.
You are simply just calling your &write_output subroutine, again and again.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me