in reply to search functionality in perl
Perl excels in text processing (note that PERL just does not exist: Perl is the language and perl is the program..).
Build up an array of files to search for. foreach one of these files open it and search in it.
You need to open the file in reading mode: see perlopentut but in short use the lexical filehandle form: foreach my $filename (@files) { open my $file_handle, '<', $filename or die "Unable to open $filename for reading!"; ...
Then you can use a while loop: see it at perlintro but pay attention to read just one line at time if the file is huge. Basically you have to do:
while (my $line = <$file_handle>){ chomp $line; ... }
After this you can use split to divide the line into fields and use a regular expression or eq to check the requested value. When this value is saved in a variable you can use it to do what do you prefere. Notice that if you need to save the result in the very same file you read, first close the filahandle and then reopen it in append mode using >>
Try the above and post here some code and tell us where you find problems.
Also be so kind to use <c> ..code tags..</c> around your code and data (you can also modify the above question).
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search functionality in perl
by Sekhar Reddy (Acolyte) on Jun 06, 2018 at 09:40 UTC |