Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created September 17, 2021 10:23
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 briandfoy/5a5b59c4b1e4a810d561cf03ba6b4bb9 to your computer and use it in GitHub Desktop.
Save briandfoy/5a5b59c4b1e4a810d561cf03ba6b4bb9 to your computer and use it in GitHub Desktop.
# Here's the input, as an indented heredoc
my $string = <<~"_STRING";
ABCD
EFGH
IJKL
ABCD
EFGH
IJKL
_STRING
# Open a filehandle on a reference to the string. Now you can read lines
# of the string
open my($sh), '<', \$string;
# read a line, then the next two. Use chomp to get rid of the newlines.
# Reconstruct the string however you like.
while( <$sh> ) {
chomp;
my @next_two = map { scalar readline($sh) } 1 .. 2;
chomp( @next_two );
say "$_|" . join ",", @next_two;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment