in reply to Reading and storing multiple lines from a file

You could use a hash-of-hashes: perldsc
use warnings; use strict; my %NX_NTF_vars; my $sec; while (<DATA>) { chomp; if (/^SECTION=(\w+)/) { $sec = $1; } if (/^NX_NTF_/) { my ($key, $value) = split("=", $_); $NX_NTF_vars{$sec}{$key} = $value; } } use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%NX_NTF_vars); __DATA__ ----- 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
$VAR1 = { 'cnt' => { 'NX_NTF_ID' => 'F9F342055699954C93DE36923835A182 +UUID String', 'NX_NTF_LAST_MOD_DT' => '02/04/2013 13:52:27', 'NX_NTF_PERSISTENT_ID' => 'cnt:F9F342055699954C93 +DE36923835A182', 'NX_NTF_PRODUCER_ID' => 'cnt' }, 'cr' => { 'NX_NTF_ID' => '400017', 'NX_NTF_NEW_DELAY_LOG' => '', 'NX_NTF_PERSISTENT_ID' => 'cr:400017', 'NX_NTF_PRODUCER_ID' => 'cr' } };

Replies are listed 'Best First'.
Re^2: Reading and storing multiple lines from a file
by shewang (Initiate) on Feb 19, 2013 at 20:20 UTC
    Thanks very much for both your responses, they both seem to do the job... but how would I go about capturing the values of each in single variables? Something like:
    my $crhandle = $NX_NTF_vars{'cr' -> 'NX_NTF_PERSISTENT_ID'}; my $cnthandle= $NX_NTF_vars{'cnt' -> 'NX_NTF_PERSISTENT_ID'};
      Ah, OK, I got it now:
      my $crHandle = $NX_NTF_vars{'cr'}{'NX_NTF_PERSISTENT_ID'}; my $cntHandle = $NX_NTF_vars{'cnt'}{'NX_NTF_PERSISTENT_ID'};

      Thanks very much for the help!