in reply to Count folder/files in directory

Inside your process subroutine you do not chance directories to the current directory you're reading nor do you use the full path of the file. Instead calling process on $_. Which begs the question why doesn't your script raise an error? It seems calling -d on the file is insufficient. I think it would be wise to test whether the file you are passing to process actually exists.

One of the reasons for not catching this bug is that you have two nearly identical pieces of code. One in your main routine and the other your process subroutine. In this case you correctly called -d on the full path in you main code but not in your subroutine. It is errors like these why programmers eschew duplication. You have the process subroutine just call it initially instead of having a separate loop in you main code.

Addendum: Your code seems to be confused about whether to use absolute or relative paths. You need to either:

  • Use relative paths; pushing the current path on a stack before calling process(), where you cd to the directory in question, then popping the saved directory upon return.
  • Use absolute paths where every call uses the full pathname. Process() being called with the full pathname and having to append the current directory to the pathname before calling itself.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}