Created
June 7, 2010 10:54
-
-
Save rjp/428530 to your computer and use it in GitHub Desktop.
This file contains 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
use IO::Scalar; | |
my $scalar = <<HEAD; | |
This is a test of the code | |
Will it work? | |
That was a blank line, this should be part 2. | |
Is this part two? | |
HEAD | |
my $output = ""; | |
my $seen_blank = undef; | |
my $io = new IO::Scalar \$scalar; | |
while (defined(my $line = $io->getline)) { | |
if ($line =~ /^\s*$/) { # blank line | |
$seen_blank = 'yes'; | |
next; | |
} | |
if (not defined $seen_blank) { | |
# process the lines before the blank | |
print ">> $line"; | |
} else { | |
$output .= $line; # might need a "\n" here | |
} | |
} | |
print "==rest==\n$output"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment