in reply to Best way to read and process a text file with multiline records

This seems to fit the bill ... unless I'm missing something:
use warnings; use strict; use Data::Dumper; my (%result, $subhash); while (<DATA>) { if (/^Data_Value/ ... /^Data_raw/) { my @value = split; my $value = $value[0] = ''; $value = "@value"; if (/^Data_Value/) { $subhash = $value; $result{$subhash} = {}; } $result{$subhash}->{Data_Group} = $value if /^Data_Group/; $result{$subhash}->{Data_raw} = $. if /^Data_raw/; } } print Dumper \%result; __DATA__ Data_Value -999 Data_Group Clock453 Data_raw -from point_q/point2 \ -of point_a/abc/Q/D \ . . -to endpoint/abc/CK Data_Value -123 Data_Group Clock453 Data_raw -from point_q/point2 \ -of point_a/abc/Q/D \ . . -to endpoint/abc/CK Data_Value -666 Data_Group Clock453 Data_raw -from point_q/point2 \ -of point_a/abc/Q/D \ . . -to endpoint/abc/CK
user@unforgiven:~$ perl tst.pl $VAR1 = { ' -123' => { 'Data_Group' => ' Clock453', 'Data_raw' => '10' }, ' -999' => { 'Data_Group' => ' Clock453', 'Data_raw' => '3' }, ' -666' => { 'Data_Group' => ' Clock453', 'Data_raw' => '17' } };
A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Best way to read and process a text file with multiline records
by tsk1979 (Scribe) on May 22, 2009 at 08:38 UTC
    Hmm the use of ellipses (...)
    This seems to be quite interesting. I have never used this to parse through multiple records

    With perl I learn everything new each day, and to consider that I have been programming for past 2 years! </p Thanks