Created
September 17, 2021 10:23
-
-
Save briandfoy/5a5b59c4b1e4a810d561cf03ba6b4bb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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