From a quick look, I don't see what is generating your output, but I do see a few things that will definitely slow you down.

1. You are reading filenames from the directory "/mnt/data/Programming", but opening those files in the current directory. If you are not in "/mnt/data/Programming", this should not open the files you intend.

2. You are modifying the directory you are reading by creating a file there. That is probably going to cause some confusion.

3. Since you are opening your output file with '>', you would overwrite it each time instead of accumulating output in that file. If you want to reopen each time, use '>>' instead.

4. You seem to be processing data one line at a time and also putting those lines in an array. I would probably only do one or the other.

I would probably get the list of files all at once and then process them from an array. For instance,

opendir ( my $dir, "/mnt/data/Programming") or die "Can't open directory: $!\n"; my @files = readdir( $dir ); closedir( $dir );

You can now process the files independently. The file open should really contain the path as well:

foreach my $file ( grep { -f "$path/$_" } @files ) { open( my $fh, '<', "$path/$file" ) or die "Unable to open '$file': $!\n"; while( <$fh> ) { # process each line here. } }

It's a good idea to check the names you get from readdir() to make sure they are files. You can't read directories as files (in general). Notice that I used lexical file and directory handles. Although not critical in this case, it will definitely save troubleshooting nasty problems in the future. Start on good habits early.

Update: Corrected file test to use path as shmem observed.

G. Wade

In reply to Re: File not opening, but no error report by gwadej
in thread File not opening, but no error report by koolgirl

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.