Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:
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($_);
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 &lt; and &gt; (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.

The code looks like this (it's a Windows NT command file, for those lucky enough to have never encountered one before):

@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
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>.

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?


In reply to Clipboard transform keys by PhilHibbs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-08-05 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?