Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created July 7, 2017 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevrah/00dee3145abac3af30ad4922903ea1a9 to your computer and use it in GitHub Desktop.
Save yevrah/00dee3145abac3af30ad4922903ea1a9 to your computer and use it in GitHub Desktop.
PERL: Multiple data sections
#!/usr/bin/env perl
# Sane defaults
use strict;
use warnings;
use feature qw/say/;
use Data::Dumper;
my @data = <DATA>;
my $files = {};
my $current = "default";
foreach my $s (@data) {
if ($s =~ m/$\@\@/ ) {
my $file = $s;
$file =~ s/\@\@\s*//g;
chomp( $file );
$current = $file;
} elsif ( $s =~ m/$\s*##/ ) {
# No Operations - these sections are pure comments
} else {
$files->{$current} .= $s;
}
}
say Dumper $files;
__DATA__
@@ myfile.html
lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. at
vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd gubergren,
no sea takimata sanctus est lorem ipsum dolor sit amet.
@@ myfile2.html
## This is a comment and wont appear!!!
## This should not appear!!!
LOREM IPSUM DOLOR SIT AMET, CONSETETUR SADIPSCING ELITR, SED DIAM NONUMY EIRMOD
TEMPOR INVIDUNT UT LABORE ET DOLORE MAGNA ALIQUYAM ERAT, SED DIAM VOLUPTUA. AT
VERO EOS ET ACCUSAM ET JUSTO DUO DOLORES ET EA REBUM. STET CLITA KASD GUBERGREN,
NO SEA TAKIMATA SANCTUS EST LOREM IPSUM DOLOR SIT AMET.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment