Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by bradenshep (Beadle)
on Nov 02, 2007 at 15:34 UTC ( [id://648666]=note: print w/replies, xml ) Need Help??


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

I like this very much! I would ask for one more feature, is this is possible. (I'm maybe 80% sure it is... this is Windows, though, so customizability is lower than I would like.)

What I want is something similar to the -- eval macro, but somewhat different. I want to be able to copy any Perl code, press a key combination (Windows+P for Perl?) and have the pasted text become the output of the Perl code. This is because often I want to run Perl code I've spotted on the web, and can't insert one of the -- macro headers.

My brain is racing ahead, coming up with so many use cases for this, both with my proposed enhancement and without. Here's a few with the existing version, for the doubters:
  • Easy sorting by arbitrary Perl-style sorting blocks
  • Applying a regex (m//, s///, tr/// the possibilities here are making me drool) to the text following.
  • Transformations with an arbitrary map, grep, reduce.
  • Web lookup (Google define, custom Mechanize scripts to collect some data off other sites)
  • eval the first line, followed by input to the evaled code.
I'm generating ideas so fast I'm forgetting them. If you do any kind of text mangling on Windows, this is a godsend.
If only I had a thousand more upvotes to give. You've made my month.

Edit: I notice it's Windows-only, but with a Unix-style shebang. I assume you have it running under Cygwin? If I want it running at startup on ActiveState, should it work?

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

    All right:

    -- def_macro eval_inplace my $count = 0; $main::c->Set("In place evaluation started. If you wish to disable, pl +ease copy -- end"); while ($main::c->WaitForChange) { $count++ % 2 or next; my $t = $main::c->GetText or next; last if $t =~ /^-- END/i; my $to = TempOut->new(); eval { eval "\$\\=\$/;$t;1" or die $@;1 } or $main::c->Set("Error +executing perl: $@ ($t)") and next; $main::c->Set($to->as_string); $to->release; } print "Exited successfully, clipcommand returned to normal";

    This is definitely a hack and shows why I need to clean up some things. However, if you run the script, copy that macro and copy -- eval_inplace, the macro will see everything you copy as perl code to execute and will dutifully populate the clipboard with its output (or the error it generated). To stop it, copy -- end. Also, you can't promote this macro and expect it to work (like I said, hack =)).

    Update: I forgot this part. I have the *nix style shebang line out of habit. I personally use it with ActiveState build 822.

      Alright, I'll have to live without it for now (not being able to promote it kind of defeats the effect) and hope for an eventual new version.

      I looked into getting it going on AS 822, but couldn't find various packages it seems to need. I'm not familiar enough with AS to know if it will work. I guess I'll just try it and see what errors come back, if any.

      Again, many, many thanks for this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found