Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: (Embed perl into your clipboard)

by antirice (Priest)
on Nov 02, 2007 at 14:28 UTC ( #648654=note: print w/replies, xml ) Need Help??

in reply to Re: (Embed perl into your clipboard)
in thread (Embed perl into your clipboard)

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


This should be the first line This should be the second line

Replies are listed 'Best First'.
Re^3: (Embed perl into your clipboard) (example)
by tye (Sage) on Nov 02, 2007 at 19:40 UTC

    I suspect some will find your example still quite unclear.

    The steps you left out boil down to something like:

    1. Get a computer running Win32.
    2. Run the script contained in the root node. Note that it will just hang out waiting.
    3. In whatever application you happen to be working in that allows you to type multiple lines of text, type in the text of the first example.
    4. Highlight the first example text that you just entered.
    5. "Cut" the example (probably by typing Ctrl-X).
    6. The script will quickly notice that something new has appeared in the cut/paste buffer (clipboard) and process it.
    7. Type, highlight, then "Cut" the second example.
    8. Type, highlight, then "Cut" (or "Copy") the third example.
    9. Wait just a little bit for the script to finish processing your third request.
    10. "Paste" (probably by typing Ctrl-V).
    11. Note that what gets pasted is the text after "Produces:"

    - tye        

      Yeah, I guess in all of my excitement I left some steps out as I figured they were implied.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://648654]
[choroba]: Yes,
[choroba]: depends on your DNS

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-05-21 12:02 GMT
Find Nodes?
    Voting Booth?