Skip to content

Instantly share code, notes, and snippets.

@flagranterror
Last active August 7, 2017 17:49
Show Gist options
  • Save flagranterror/ce114f762dc13ac25eb1ef3a69b80bea to your computer and use it in GitHub Desktop.
Save flagranterror/ce114f762dc13ac25eb1ef3a69b80bea to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# perlsplit.pl input.txt
open(INPUT, $ARGV[0]);
open($dec,">" , "decoder.txt");
open($enc,">" , "encoder.txt");
my @array;
{
local $/ = '';
@array = <INPUT>;
}
my $header = 1;
my $section = 'unknown';
foreach(@array) {
if ($header) {
chomp;
$section = $_;
print $dec "$section";
print $enc "$section";
} else {
my @lines = split('\n', $_);
foreach(@lines) {
print $enc "$_\n";
print $dec "$section";
}
}
$header = !$header;
}
close $dec;
close $enc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment