in reply to Extract information from several files in directory

I have previously managed to do this with one file

That's a good place to start. Might I suggest the following approach to help extend this to several files?

  1. Take your working code and move it into a subroutine (see perlsub) which takes the filename to be read as the only argument. Confirm the script still works as before.
  2. Now simply call the subroutine twice in the script with a different filename each time. Confirm that the script produces the output you expect for two input files.
  3. Now write your loop to find all the files in the directory and just call the subroutine from within the loop. You should now have output from all the files.

Portioning up the code into smaller blocks (such as using subroutines) helps you to work on small parts of a larger problem in isolation. If you have specific problems with any particular part feel free to ask. Remember that an SSCCE is best. Good luck.


🦛

  • Comment on Re: Extract information from several files in directory