<?xml version="1.0" encoding="windows-1252"?>
<node id="648654" title="Re^2: clipcommand.pl (Embed perl into your clipboard)" created="2007-11-02 10:28:28" updated="2007-11-02 06:28:28">
<type id="11">
note</type>
<author id="227499">
antirice</author>
<data>
<field name="doctext">
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;The reason for [cpan://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.&lt;/p&gt;
&lt;p&gt;As for another example, here's a simple note/recall pair of macros.&lt;/p&gt;
&lt;code&gt;
-- def_macro note
my $file = shift or die "Please indicate the note you wish to create/append to";
mkdir 'notes' unless -e 'notes';
open my $fh, "&gt;&gt;", "notes/$file" or die "Couldn't open note for write: $!";
local $/;
print $fh $_ while &lt;&gt;;
close $fh or die "Trouble closing file: $!";
print "Successfully appended to note $file";
&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;
-- 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, "&lt;", "notes/$file" or die "Couldn't open note for read: $!";
local ($/,$\);
print &lt;$fh&gt;;
close $fh or die "Couldn't close file: $!";
&lt;/code&gt;
&lt;p&gt;To use:&lt;/p&gt;
&lt;code&gt;
-- note example
This should be the first line
&lt;/code&gt;
&lt;code&gt;
-- note example
This should be the second line
&lt;/code&gt;
&lt;code&gt;
-- recall example
&lt;/code&gt;
&lt;p&gt;Produces:&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;
This should be the first line
This should be the second line

&lt;/code&gt;
&lt;/p&gt;
</field>
<field name="root_node">
648493</field>
<field name="parent_node">
648630</field>
</data>
</node>
