Here are some code snippets using interpolation that you may find useful to put in your toolbox. While these are specific to Perl, it's easy to see how they could be adapted to other languages. Note that these snippets ask you to fill in the blanks as you code and help speed up development by taking care of some of the mundane tasks (like adding comments at the end of a conditional block).
------------------------------------------------------------------- Perl elsif:
elsif ([[%ask1:Condition:1]]) {
# Do this when true
} ## END OF elsif ([[%ask1]])
-------------------------------------------------------------------
Perl foreach
foreach [[%ask1:IndexVariable:$i]] ([[%ask2:ArrayVariable:@list]]) {
# Do something with [[%ask1]]
} # END OF foreach [[%ask1]] ([[%ask2]])
-------------------------------------------------------------------
Perl if/else
if ([[%ask1:Condition:1]]) {
# True
}
else { # else from if ([[%ask1]])
# Otherwise
} # END OF if ([[%ask1]])
-------------------------------------------------------------------
Perl sub (no POD)
##############################################################################
# [[%ask:Describe this subroutine:What does it do?]]
sub [[%ask1:Subroutine Definition:my_sub()]] {
# Do something here
} ## END OF [[%ask1]]
-------------------------------------------------------------------
Perl sub (with POD)
##############################################################################
=item C<[[%ask1:Subroutine Definition:my_sub()]]>
[[%ask:Describe this subroutine:What does it do?]]
=cut
sub [[%ask1]] {
# Do something here
} ## END OF [[%ask1]]
-------------------------------------------------------------------
Perl while
# What is ths while about?
while ([[%ask1:Condition]]) {
# Code goes here
} ## END OF while ([[%ask1]])
-------------------------------------------------------------------
If you can think of others you think would be useful, please feel free to contribute them here. These snippets of code, created by myself, Kevin Benton are entered into the public domain.
Some more snippets, specifically POD related:
POD Formatting Codes
I<<<[[%ask:Italic Text]]>>>B<<<[[%ask:Bold Text]]>>>C<<<[[%ask:Code]]>>>L<<<[[%ask:Link Location]]>>>E<<<[[%ask:Escape Code]]>>>F<<<[[%ask:File Name]]>>>S<<<[[%ask:Text that should not be broken across lines]]>>>X<<<[[%ask:Index Entry]]>>>Z<<<>>>__END__---
Kevin Benton
Good stuff. I also find it useful to bind a quick key to "=pod\n=head2\n" and another to "=cut" to encourage myself to use more POD :-)
Hi,
This code could also work as a one-liner. It opens the filename specified when calling the script. Reads all its content in the $cnt scalar and then prints it as if it were a cat instruction. By uncommenting some lines it could even list each line with a linenumber.
It makes reading files as easy as typing cat.
{ # S.L.U.R.P. input file (STDIN)
local $/;
push(@ARGV,shift);
$cnt=<>
}
## UNCOMMENT THE FOLLOWING LINES TO LIST IT WITH LINENUMBERS...
#my $nr=1; $cnt= join("\n",(
#map{
# sprintf("%03i_ %-60s",$nr++,$_)## LNUM_ LINE...
# }( split(/[\r\n]/, $cnt) ) ## SPLIT BY LF
#)
# );
print($cnt,$/); ## CAT: PRINT THE FILE CONTENT
People is born original
and dies as a copy
Alberto