Skip to content

Instantly share code, notes, and snippets.

@rjp
Created June 7, 2010 10:54
Show Gist options
  • Save rjp/428530 to your computer and use it in GitHub Desktop.
Save rjp/428530 to your computer and use it in GitHub Desktop.
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