📘 Skipping Pod documentation in Perl 6

Create the program that copies the input text and skips the documentation in the Pod style that starts with =begin and ends with =end.

Let us take a simple text containing a piece of Pod documentation:

# Hello, World!
This program prints a message
say 'Hello, World!';

The program should read it and print everything that is not the comment. Thus, for the given example, only the first and the last lines can go to the output.

In Perl 6, there is a family of flipflop operators that, although being a bit hard to understand at first, are quite powerful for introducing the two-state triggers in the program flow.

while $_ = $*IN.get {
    .say unless /^'=begin'/ ff /^'=end'/;

Reading lines from the STDIN handle is the same as it will be done it in task 95, The catutility. The flipflop construct /^'=begin'/ ff /^'=end'/ is False initially and becomes True as soon as the $_ content matches the first regex. After that, it stays True until the second condition is True. In the end, the unless clause only passes the lines that are not located between the =begin and =end instructions. The .say method call is thus printing all the remaining lines.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s