So I have a config file which I need to read into a perl script and store in variables to use later in the process.
The file looks like so:
----- SECTION=cr NX_NTF_ID=400017 NX_NTF_PRODUCER_ID=cr NX_NTF_PERSISTENT_ID=cr:400017 NX_NTF_NEW_DELAY_LOG= ----- SECTION=cnt NX_NTF_ID=F9F342055699954C93DE36923835A182 UUID String NX_NTF_PRODUCER_ID=cnt NX_NTF_PERSISTENT_ID=cnt:F9F342055699954C93DE36923835A182 NX_NTF_LAST_MOD_DT=02/04/2013 13:52:27
The code I have done to date reads in the file and stores the values in variable names consistent with what they are in the file.
my $input = "..//NX.env"; open(NX_ENV, "<", $input) or die "Can't open input file $input\n"; my %NX_NTF_vars; while (<NX_ENV>) { chomp; if ($_ =~ /^NX_NTF_/) { my ($key, $value) = split("=", $_); $NX_NTF_vars{$key} = $value; }; };
I then use the following to set my variables for later use:
my $NTF_ID = $NX_NTF_vars{'NX_NTF_ID'}; my $NTF_PROD = $NX_NTF_vars{'NX_NTF_PRODUCER'}; my $NTF_PID = $NX_NTF_vars{'NX_NTF_PERSISTENT_ID'};
However, you can probably see the problem here... as there's an entry for NX_NTF_PERSISTENT_ID under the section headed SECTION=cr and an entry under SECTION=cnt.
So I need to know if there's a way of prefixing the $key variables with the name from the SECTION line?
Any advice greatly received!
In reply to Reading and storing multiple lines from a file by shewang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |