Hi Everyone,
I'm new the forum and also Newbie to Perl programming. Please go easy on me.
Any help or input will be appreciated.
Thanks so much.
Ragards,
Vincent.
I have the following requirements that need to write in Perl.
Sorry for the long sentences below. Also please see attached for the same.
I tried to be clear as possible.
Basically, there are 2 input files (input file & validation rule file) and write to one output file
Each input file has one or more records. Each record has multiple rows.
For a given record, given row need to compare the key values against the validation file
if key founds then based on the validation rules
for examples, validation can be exact match compare, pattern match compare and etc...
I need only to write out the unmatched/failed rows.
Input file - tilda delimiter file without header record
c:\input.txt
file layout as below.
object type 0 = File Name,
object type 1 = Record name,
object type 2 = job parameter,
object type 5 = operator properties
object type~object name~object values
object type & objet name are the key columns to compare to input validation rule file
0~File Name~input.txt
1~First record~record 1
2~ARRAY_SIZE~xxx
5~Server~[&"$TD_DB_SERVER"]
5~Variant~3
0~File Name~input.txt
1~Second record~record 2
2~ARRAY_SIZE~2000
5~Variant~12
0~File Name~input.txt
1~Third record~record 3
2~ARRAY_SIZE~2500
5~Variant~
5~Server~"USER"
Input Validation rule - tilda delimiter file without header record
file c:\valadation.txt
file layout as below.
Environment~object type~object name~object values~validation rule~message
object type & objet name are the keys column to compare to input file
source_to_landing~5~Server~$TD.*SERVER*~must_match_pattern~Error
source_to_landing~5~Variant~(12,8)~match_any_in_list~Error
source_to_landing~5~ArraySize~check_integer~Check_to_see_if_integer~Warning
Logic:
read in c:\input.txt
read in c:\valadation.txt (as lookup file)
compare the keys object type & objet name from 2 files
I think I need to have 2 loops
Step A, Outter loop will be reading each input record into memory until end of the file
Then perform Step B - the inner loop will be the performing the following checking until end of the record
For each record
read the validation file
step 1,
If key columns found
then check the validation rule column from the c:\valadation.txt file
If validation rule = 'match_any_in_list'
then get the corresponding object value column from the input file
and compare against the list of values defined in the object values column in the validation file
Else If validation rule = 'must_match_pattern'
then get the corresponding object value column from the input file
and compare against the pattern literal defined in the object values column in the validation file
Else If validation rule = 'check_integer'
then validate against corresponding object value column from the input file to see if the value is integer
End
when Unmatched, write the unmatched row from current record into output file (please see output layout below)
Read next row from the current record and go back to step 1 above until end of input record
Go back to Step A and read next record until end of the file
Output file.
/* expected output for the first record from the input file */
0~File Name~input.txt
1~First record~record 1
2~ARRAY_SIZE~xxx~Check_to_see_if_integer~Warning
5~Variant~3~match_any_in_list~Error
/* expected output for the third record from the input file */
0~File Name~input.txt
1~Third record~record 3
5~Variant~match_any_in_list~Error
5~Server~"USER"~must_match_pattern~Error