in reply to Storing multiple blocks of text in the __DATA__ section
(Note that in this example the final new-lines are retained in the values.)#!/usr/bin/perl use strict; use warnings; my %structure; { local $/ = ""; # input record separator = empty string for "parag +raph mode" while (<DATA>) { s/^(.*)\n//; # first line is key string $structure{$1} = $_; } } print "key: $_ / value:\n$structure{$_}\n----\n" for ( sort keys %stru +cture ); __DATA__ first_key Here's some data to go with the first key key_3 Third key gets this part key number 2 This element of %structure has spaces in the hash key.
UPDATED to localize the use of paragraph-mode.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Storing multiple blocks of text in the __DATA__ section
by LanX (Saint) on Jan 02, 2015 at 17:29 UTC | |
by graff (Chancellor) on Jan 02, 2015 at 17:55 UTC | |
by blindluke (Hermit) on Jan 03, 2015 at 13:53 UTC |