So naturally the file is huge? Any suggestions?

First whitespace is your friend aka learn how to format and indent your code.

Second every time you find a file that ends in .9 you overwrite the file 'adjusted.learn' (if there is more than one in that dir) with the '#do something' processed content of the .9 file so there is absolutely no possibility whatsoever of the 'adjusted.learn' file ever getting bigger than the size of the largest 'do something' munged .9 file in that dir unless you are doing something to make that so.

Here is your code. I have formatted it and changed a few minor things. Have a look at the changes..... besides the whitespace there are useful error messages like can't read (this file name in this dir) because of this reason rather than what your code would generate - ie cannot read file: access denied. That sort of error is useless. We know there is a problem. But what the hell is it! If you write code like you have presented you may as well write open F, $file or die "Error 123\n" for all the informative value you are adding. The only things you will genreally ever see in $! are 'access denied' or 'file does not exist', but you really want to know WHICH FILE WHERE?

Also if you get data in $_ in a sub it is generally not a good idea to mess with $_ withing that sub. See the while loop.

Leaving all that asside if you set $/ the input record separator to 'blah blah blah' and the string 'blah blah blah' does not appear in the input file you will read the entire file into memory as a single record. Thus $outlines[0] will contain the entire file content. It that your real problem?

find (\&process, $folder); sub process { if ($_ =~ /\.9$/) { print "\nProcessing file $File::Find::dir/$_\n"; open FILE, $_ or die "Cannot read $File::Find::name: $!"; local $/= "# input for"; # localise @outlines so we don't accumulate my @outlines = (); while ( my $line = <FILE> ) { #do something push @outLines, $line; } close FILE; my $out = 'adjusted.learn'; open OUTFILE, ">$out" or die "Cannot write $out: $!"; print OUTFILE @outLines; close OUTFILE; } } exit;

cheers

tachyon


In reply to Re: Working with Subfolder by tachyon
in thread Working with Subfolder by Anonymous Monk

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.