1.Search a file for a common user entered phrase. 2.Loop through each file within a directory for a user entered phrase.Here is one way to print all lines of all files in the current directory which contain a phrase:
use strict; use warnings; use File::Slurp qw(read_dir); my $phrase = shift; for my $file (grep { -f } read_dir('./')) { open my $fh, '<', $file or die "can not open $file: $!"; while (<$fh>) { print if /$phrase/; } close $fh; }
See also perlintro (especially Files and I/O), File::Slurp and grep.
The Monastery has its own Tutorials to complement those on the official documentation website: Getting Started with Perl
In reply to Re: File Analysis
by toolic
in thread File Analysis
by t3hshadow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |