Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2019-11-12 05:53 GMT
    Find Nodes?
      Voting Booth?
      Strict and warnings: which comes first?

      Results (64 votes). Check out past polls.