In reference to your update the example posted is already generic and does exactly as you suggest with a minute change. Have a look at the Data::Dumper output. You have a hash of arrays keyed on the HEADER|TITLE|COMPND tokens. Each element in the arrays is the concatenated contiguous lines. You would reference one array like @{$hash{HEADER}} or a single element like $hash{HEADER}->[2]
my %hash; my $current_token = ''; $re_types = qr/(HEADER|TITLE|COMPND)/; while (<DATA>) { my ($token, $value ) = $_ =~ m/^$re_types\s+(.*)/; next unless $token; if ( $token eq $current_token ) { ${$hash{$token}}[-1] .= ' ' . $value; } else { $current_token = $token; push @{$hash{$token}}, $value; } } use Data::Dumper; print Dumper \%hash; __DATA__ blah
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: An (almost) useful idiom; needs work.
by tachyon
in thread An (almost) useful idiom; needs work.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |