Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: clipcommand.pl (Embed perl into your clipboard)

by Anonymous Monk
on Nov 02, 2007 at 12:24 UTC ( [id://648630]=note: print w/replies, xml ) Need Help??


in reply to clipcommand.pl (Embed perl into your clipboard)

Interesting, but how does this work? What is "--"? Why do you need B::Deparse? Some more examples, please!
And this is win32 only, right?

Replies are listed 'Best First'.
Re^2: clipcommand.pl (Embed perl into your clipboard)
by antirice (Priest) on Nov 02, 2007 at 14:28 UTC

    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

      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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://648630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-03-28 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found