It's really tedious to need to correct code and example output after spotting a flaw.
That's why I just hacked PM.pl to automatically wrap code-tags around my combined source-file and output, so I just need one copy and paste.
Just put it into the same directory like your other scripts.
Activate it just with do "./PM.pl" inside your source file.
It requires a __DATA__ at the end of your source code and will warn you otherwise
NB: The do PM.pl; is omitted as is __DATA__ if it's the last line.
use v5.12; use warnings; do './PM.pl'; say for <DATA> __DATA__ 1 2 3
<code> use v5.12; use warnings; say for <DATA> __DATA__ 1 2 3 </code> OUTPUT: <blockquote><i><code> 1 2 3 </code></i></blockquote>
OUTPUT:use v5.12; use warnings; say for <DATA> __DATA__ 1 2 3
1 2 3
The code is pretty self explanatory, you can adjust it to your needs
package PM; use v5.12; use warnings; use Scalar::Util qw/openhandle/; my ($pck) = caller() // __PACKAGE__; my $data = eval "\\*${pck}::DATA"; # *DATA of caller my $ctag = "code"; # avoid messup local $|=1; unless ( openhandle($data) ) { warn "__DATA__ missing, can't format source code"; } else { my $current_pos = tell $data; seek $data,0,0; say "<$ctag>"; while ( <$data> ) { print unless # ignore ... /^(do)\s.*PM/ # . do PM.pl or /^__DATA__/ && eof($data); # . __DATA__ on last line } say "</$ctag>"; seek $data,$current_pos,0; } say "OUTPUT: <blockquote><i><$ctag>"; END { say "</$ctag></i></blockquote>" }; __DATA__
UPDATE: fixed localization of non-buffering
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Helper script to format code and output to perlmonks markup by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |