Actually, it reacts to commands that start with - or '-. The reason I use -- is because I normally use it with SQL Server to generate scripts. The reason for the '- is because I also use VB (yes, boo hiss =/). I work in a Microsoft-only shop and I find that the languages I need to use benefit greatly from code generation.
The reason for B::Deparse is so the script can get the source for the anonymous subs that have been generated. If you wish to see the entire subroutine that is generated for a macro, use the fullcodefor macro. codefor reconstructs the macro as you gave it, although it does a bit of cleaning up which I like.
As for another example, here's a simple note/recall pair of macros.
-- def_macro note
my $file = shift or die "Please indicate the note you wish to create/a
+ppend to";
mkdir 'notes' unless -e 'notes';
open my $fh, ">>", "notes/$file" or die "Couldn't open note for write:
+ $!";
local $/;
print $fh $_ while <>;
close $fh or die "Trouble closing file: $!";
print "Successfully appended to note $file";
-- def_macro recall
my $file = shift or die "Please indicate the note you wish to open";
die "Note $file does not exist" unless -f "notes/$file";
open my $fh, "<", "notes/$file" or die "Couldn't open note for read: $
+!";
local ($/,$\);
print <$fh>;
close $fh or die "Couldn't close file: $!";
To use:
-- note example
This should be the first line
-- note example
This should be the second line
-- recall example
Produces:
This should be the first line
This should be the second line
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.