in reply to Re: Readdir against large number of files
in thread Readdir against large number of files

Thanks for the help. I gave your code a try but it is only printing the line STRUC20. What I was looking to do is print all lines in the file after STRUC20. And also all files online contain the line STRUC20 once and they will all contain that line.
Thanks again for all the help.

Example file contents of file1.rtsd001
date time blah blah test test STRUC20 #Code should look for this line and print everything after it +. need lines need lines print these lines

Replies are listed 'Best First'.
Re^3: Readdir against large number of files
by almut (Canon) on Oct 28, 2009 at 19:03 UTC
    What I was looking to do is print all lines in the file after STRUC20

    The flip-flop operator (aka the range operator .. in scalar context) might come in handy for that:

    while (<UNMODIFIED>) { print MODIFIED $_ unless 1 .. /STRUC20/; # i.e. do print, except for first line upto a line that matches ST +RUC20 }
Re^3: Readdir against large number of files
by moritz (Cardinal) on Oct 28, 2009 at 18:45 UTC

    You're right, I didn't read your original code carefully enough.

    You can introduce a variable that stores if it's after the STRUC20 line:

    while (my $matchingFiles = glob("*.rtsd001")) { ... my $seen_struct; while (<UNMODIFIED>) { if ($seen_struct || /STRUCT20/) { $seen_struct = 1; print MODIFIED $_; } } ... }

    That way you don't have to store all the rest of the lines in memory, and still get the same semantics.

    Update: actually this solution looks more elegant, but does nearly the same thing.

    Perl 6 - links to (nearly) everything that is Perl 6.