I use NT4 and Win2K at work. My main use for Perl is as a productivity tool, and a lot of the scripts I use take the text out of the Win32::Clipboard, do something to it, then put it back. I then make a shortcut (.lnk) to the script, put it in Accessories in my Start menu, and assign a double bucky to it. I can then run my transforms by copying the source info into the clipboard, hit the magic key, watch the black box of a command prompt flicker in and out of view (sometimes takes a second on NT, much quicker on Win2K), then paste the results. The most recent one I did was this:
Then I can build up mathematical equations in my text editor, and evaluate them without having to run Calculator and alt-tab back and forth all the time. Update: Added X and x functions to convert to hex. Other tricks include converting a vertical list of values into a comma-separated quoted list that breaks after 72 characters, trim all trailing spaces, adding <href=" to the start and "></a> to the end (I've used that one a couple of times in this writeup), convert < and > to < and > (and I'm considering writing one that prepends and appends <code> and </code>!), and the one that I use perhaps the most, does nothing apart from read the clipboard, and write it back again. Why? Because it throws away any formatting. If you right-click and copy a URI in IE, and paste it into Outlook, it becomes a .URL attachment. If I hit the appropriate key, then it gets pasted in as plain text. If I hit another key, it gets wrapped in a <a href=""></a> tag set ready for pasting into an HTML file, a Slashdot comment, or a Perl Monks writeup. I just wrote the <CODE></CODE> wrapper, it took me exactly one minute to write it (excluding the later addition of the <code></code> protection), make the shortcut, move it into the Start menu, and assign a key to it.sub X { return X($_[0]); } sub x { return sprintf("%x",$_[0]); } my $CLIP = Win32::Clipboard(); my $text = $CLIP->GetText(); my $result; print '$_='.$text."\n"; eval('$_='.$text); print $_."\n"; $CLIP->Set($_);
The code looks like this (it's a Windows NT command file, for those lucky enough to have never encountered one before):
At first I was breaking the </CODE> by inserting </CODE><CODE> inside it, but it appears that if there are line breaks within the <CODE></CODE> block, then it is assumed that there should be one at the end as well. Then I used <pre> instead of <code> in this writeup in order to get that last </CODE> to display correctly. Now I just change the original perl code so that it no longer contains </code>.@rem = '--*-Perl-*-- @echo off perl -x -S "%~dpnx0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl @rem '; #!perl #line 8 use strict; use warnings; use Win32::Clipboard; my $CLIP = Win32::Clipboard(); my $text = $CLIP->GetText; $text =~ s|</ code>|</</ code><code>code>|gx; $CLIP->Set('<<i></i>code>'.$text.'<'.'/code>'); __END__ :endofperl
My head really hurts.
In addition, of course, I write the occasional I/O filter for text file transformations or greps, but there's nothing innovative about them.
Update: Is there a way to do this kind of thing in Linux?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Clipboard transform keys
by halley (Prior) on Aug 06, 2003 at 16:42 UTC | |
by PhilHibbs (Hermit) on Aug 19, 2003 at 18:04 UTC | |
by John M. Dlugosz (Monsignor) on Sep 04, 2003 at 19:33 UTC | |
by PhilHibbs (Hermit) on Sep 16, 2003 at 13:28 UTC | |
Clipboard transform key: Comma-separated list maker
by PhilHibbs (Hermit) on Aug 19, 2003 at 18:20 UTC | |
Clipboard transform key: Text to HTML for PerlMonks
by PhilHibbs (Hermit) on Aug 19, 2003 at 18:08 UTC | |
Advanced Clipboard transform keys
by Koosemose (Pilgrim) on Mar 03, 2004 at 10:01 UTC | |
Re: Clipboard transform keys
by Freddo (Acolyte) on Aug 12, 2003 at 00:33 UTC | |
by PhilHibbs (Hermit) on Aug 18, 2003 at 10:48 UTC | |
by John M. Dlugosz (Monsignor) on Sep 04, 2003 at 19:37 UTC | |
Re: Clipboard transform keys
by PhilHibbs (Hermit) on Aug 16, 2004 at 11:39 UTC | |
Re: Clipboard transform keys
by PhilHibbs (Hermit) on Sep 16, 2003 at 12:46 UTC | |
Re: Clipboard transform keys
by Anonymous Monk on Nov 13, 2003 at 12:48 UTC | |
by PhilHibbs (Hermit) on Nov 13, 2003 at 15:01 UTC | |
Re: Clipboard transform keys
by PhilHibbs (Hermit) on Jun 25, 2004 at 11:16 UTC | |
Clipboard transform key: scraper_help
by PhilHibbs (Hermit) on Nov 13, 2003 at 12:29 UTC | |
Clipboard transform key: de-dupe blank columns
by PhilHibbs (Hermit) on Nov 13, 2003 at 12:34 UTC | |
Re: Clipboard transform keys
by phildog (Novice) on Aug 14, 2003 at 16:55 UTC | |
by PhilHibbs (Hermit) on Aug 18, 2003 at 10:15 UTC |
Back to
Cool Uses for Perl