in reply to how to open all file one by one

use strict; use warnings; my @txtfiles = glob "*.txt"; my @criticalfiles; for my $file (@txtfiles) { my $fh; if( not open $fh, "<", $file ) { print "Cannot open file $file, skipping.\n"; next; } while( <$fh> ) { if( /critical/ ) { push @criticalfiles, $file; last; } } close $fh; } print "Critical files:\n"; print join( "\n", @criticalfiles ), "\n";

Replies are listed 'Best First'.
Re^2: how to open all file one by one
by GordonLim (Acolyte) on Apr 12, 2013 at 15:14 UTC
    Thanks, this script list out which txt file got critical word, but what I want is to list out the data inside the txt file. Can you advise me? :)
      Yes.

      I advise you to do some reading of documents (perlintro might be a good place to start); to study some of the relevant tutorials here; to use bigG or Super Search to find threads dealing with similar question; and most especially. to do some work on your own. Then ask again, if you get stuck with an honest effort.

      This is NOT a freee code-writing service. PerlMonks exists to help you learn.

      If you didn't program your executable by toggling in binary, it wasn't really programming!

        Ok, yeah you are right, my basic is not strong enough, should search more basic to read. Thanks for your advice.