in reply to Loop is not working
Welcome to Perl and PerlMonks, ozdemmer!
There are quite a few things that should be improved in your script. First of all, you should start your script with the following, which is explained in Use strict and warnings and the Basic debugging checklist:
#!/usr/bin/perl use warnings; use strict; use diagnostics;
When you do this, you will unfortunately see quite a few errors that you need to fix. For example, cd .. is not valid Perl (chdir is the right function), and you'll need to declare variables like @files and $s before using them. Also, you should be checking for errors in several more places, such as opendir (opendir my $dh, '.' or die "opendir: $!";) and chdir. This might seem a bit tedious at first, but in the long run, it will make for much better code, which is why these are important habits to get into.
I think you might benefit from a read of perlintro. Among other things, you'll be introduced to some of the basic ways to process files. Tie::File is a good start, but note that it is quite inefficient - when you're processing files line-by-line, a while loop will be better. A few more notes:
Now, on to your issue: You say you want to work on multiple files, but I see that you are doing chdir "/mnt/hgfs/ExpAutism/Scripts"; (a fixed directory) and then operating on a file Level1Run1_spec.fsf (also a fixed filename). I think your loop probably is running twice, but you're always operating on the same files. I don't see where the filenames you've specified in @files come into play?
Thank you for posting your code and output. Could you please describe your input and expected behavior more? For example, I don't know if SubjectASD202 and SubjectASD203 are files or maybe directories, whether they are located in /mnt/hgfs/ExpAutism/Scripts or somewhere else, and so on. The best thing you can do, and the way you'll get help the quickest, is if you could post a Short, Self-Contained, Correct Example: something that we can just download and run and debug for ourselves.
|
|---|