rahulme81 has asked for the wisdom of the Perl Monks concerning the following question:
I need to use array elements while pattern matching.
@myarr = (ELEM-1, ELEM-2, ELEM-3,ITEM-1,ITEM-2,ITEM3);ELEM-1, ELEM-2, ELEM-3,ITEM-1,ITEM-2,ITEM3 are the distinct column values from a file which I read in beginning of my scripts and store them in @myarr.
Basically What I intend to do is
1. If my @myarr = (ITEM-1,ITEM-2,ITEM3) ==> I print all the information from items.txt file.
2. If my @myarr = (ELEM-1, ELEM-2, ELEM-3) ==> I print all the information from elem.txt file.
3. If my @myarr = (ELEM-3,ITEM-1,ITEM-2,ITEM3)
==> I want to print all the information from items.txt file + Some few lines for elem.txt (Based on Pattern Match in file with keyword ELEM-3 in @myarr)
I am able to code the things for 1 and 2 but not not able to achieve my Point 3 If my @myarr = (ELEM-3,ITEM-1,ITEM-2,ITEM3)
I need a generic code instead of hardcoding the array elements inside the code since array elements are not known & may vary.
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl:Use of array elements in pattern matching
by Laurent_R (Canon) on Aug 29, 2016 at 06:15 UTC | |
|
Re: Perl:Use of array elements in pattern matching
by Anonymous Monk on Aug 29, 2016 at 04:21 UTC | |
by rahulme81 (Sexton) on Aug 29, 2016 at 05:05 UTC | |
by Anonymous Monk on Aug 29, 2016 at 07:13 UTC |