I like to browse CPAN. Usually when I fetch a new module I extract the code of the modules SYNOPSIS POD section to a small test script and then toy with it.
For most Modules the code is executable with a few modifications. Sometimes one don't even have to modify anything.
For these Modules I wrote a small Perl/Shell script perlsyno. Calling the script is a straightforward "perlsyno CPAN::Module". This extracts the perltidied and unindented code from the Synopsis.
The optional switch -e can be used to execute the code directly.#!/bin/bash # usage: perlsyno [-e] CPAN::Module function syno { perldoc -tT $1 |\ perl -0777 -ne 'print /^SYNOPSIS(.*?)^\w/ms;'|\ perltidy -i 0 } [ $# -gt 0 ] || exit 1 if [ "$1" = "-e" ] then shift [ $# -gt 0 ] || exit 1 syno $1 | perl -0777 -ne 'eval $_' exit 0 fi syno $1
$ perlsyno -e Acme::Terror Current terror alert level is: ELEVATED
In reply to extract SYNOPSIS code samples by codeacrobat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |