in reply to Re: Storing multiple blocks of text in the __DATA__ section
in thread Storing multiple blocks of text in the __DATA__ section
The OP wanted to allow multiple paragraphs in one section, and IMHO this isn't easily done with $/ .
E.g using multiple newlines like in "\n\n" is a bit too error-prone and other separators would be part of the sections and needed to be filtered again.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
use Data::Dump; my %desc=init_data(); dd \%desc; sub init_data { my $sep = "\n=====\n"; local $/ = $sep; my %hash; while (<DATA>) { s/$sep$//; # kill separator s/^(.*)\n//; # first line is key string $hash{$1} = $_; } return %hash; } __DATA__ ONE one ===== TWO two two ===== THREE Three three
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Storing multiple blocks of text in the __DATA__ section
by graff (Chancellor) on Jan 02, 2015 at 17:55 UTC | |
by blindluke (Hermit) on Jan 03, 2015 at 13:53 UTC |