Quote:
Originally posted by rdove
My task requires me to write all my information to a text file. Now the next thing they want is for me to get certain information from the text file based on critera. Kind of like SQL in a database only I must use a text file.
Anyone have any great linksor advice that deals with searching through information in a text file with perl?
Thanks
|
Code Examples may be of some help. I like
Perl Monks, too. In the mean time, is this what you're trying to do? Or is it more complicated?
Code:
open (IN, "file") or die "Can't read file: $!\n";
while ( <IN>) {
chomp;
my @fields = split;
if ($fields[0] =~ /PATTERN/) {
# do something
}
}
close(IN);
Here's how you can simply get a list of all lines containing a certain pattern:
Code:
open (IN, "file") or die "Can't read file: $!\n";
my @lines = <IN>;
my @stuff = grep { /PATTERN/ } @lines;
print @stuff;
close(IN);