Various comments.

  1. You are synchronizing two parts of your code with numerical codes. These will become problematic to keep in sync. It is better to build one data structure with all of the necessary information and then loop through it a couple of times to produce both data structures, thereby keeping like stuff together. For instance have an array with elements like
    ['To Mixed Case', sub { tr/A-Z/a-z/; s/\b(.)/uc($1)/ge; }],
    and then use the first field as the text, and build up a function lookup hash used in the run() function instead of your current case. (Pass the text to the run() function and then there is no synchronization needed.)
  2. Note that above I used $_. Since you are likely to write many cases, and commands default to $_, for this special purpose program I think that $_ makes sense.
  3. You are limiting the user to only the commands that you have thought of and pre-built. I would recommend adding in commands where the execution of the command depends on a text field where the user can enter something more sophisticated - for instance their own substitution, arbitrary code, the name of a file to save the clipboard in and so on. Note that this will make your Tk display necessarily more complex, and complicates the first suggestion that I made. Solving that is left as an exercise to the reader...
  4. You will eventually run across the fact that Win32::Clipboard leaves line endings as \r\n. It is convenient to convert \r\n into \n on the way into the run() function, and convert \n back into \r\n on the way out.
  5. Your assumption that this can be modified for other operating systems is only partially correct. The *nix model of having selecting text be the same as putting it into the clipboard makes using a tool like the above be inconvenient for in place editing. You select text, edit the clipboard, then you have to go back and paste it, then reselect, and then delete the original. Ugh. You would be better advised to use hooks in your editor.
  6. In fact my final suggestion is to just learn your editor better. I say this because a clipboard editor (command line, but on the same principle as the above) was the first useful program that I wrote for myself in Perl. I learned this program, with the result that for a long time I used my homegrown tool rather than learning my editor better. But long-term, I think that learning the editor is likely to be more productive.
I hope that this feedback proves useful to you.

In reply to Re: One button text processing by tilly
in thread One button text processing by nysus

Title:
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, details, 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, summary, 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.