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.


In reply to Re: Loop is not working by haukex
in thread Loop is not working by ozdemmer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.