I use this to drop text "formatting" (i.e. markup, RTF, etc) when I'm copying and pasting under Windows.

Say you've got two email messages open, one you've received and one you're composing in reply. You want to copy a sentence into your reply, but when you paste you get the unwanted font, color, size etc of the original email.

For convenience I've bound this script to a hot-key <Win>-X so I can <CTRL>-C, <Win>-X, <CTRL>-V.

I used to do this by opening a plain-text editor (gvim), pasting, then copying again.

# Ridiculously simple, but very useful.
use Win32::Clipboard;
my $text = Win32::Clipboard::GetText() or exit;
Win32::Clipboard($text) if $text;
Replies are listed 'Best First'.
Re: Drop formatting to paste plain text from Clipboard
by chanio (Priest) on Mar 27, 2007 at 18:01 UTC
    Actually, I am fond of these simple tasks that can make our lives easier...

    When I call this script I use to mention one or two arguments that would make additional effects to the text...

    The following code, adds some formating to the text. By default, it writes columns of 60 characters. But it is possible to specify any number of columns.

    my $cant; $cant =shift || 60 ; ## DEFAULT: 60 COLS. use Text::Format; my $anco; ## 1ST.LINE LEFT MARGIN $anco = length($1) if ($text=~/^( +)/);## MARGIN? $anco = 0 if ($anco < 1 or $anco >= $cant);## ERROR? $cant -= $anco; ## FORMAT WITHOUT LEFT MARGIN TO ADD my @tod = (split(/\n+ */,$text)); $text=new Text::Format({ columns => $cant, text => \@tod, justify => 1, firstIndent => 0}); $result.= join(" ", ($text->paragraphs())); if ($anco) ## FORMAT WITH 1ST. LINE MARGIN... { @tod= (split(/\n+ */,$result));## GET EVERY LINE my $cant= ' ' x $anco; ## LEFT MARGIN IN SPACES $result = $cant. join("\n$cant",@tod); ## ADD LEFT MARGIN AND OUTPUT } $CLIP->Set($result); ## TO THE CLIPBOARD...
    I can also transform plain text into HTML code, extract certain phrases with REGEX, transform the text into a commented block, unescape characters or escape them, sort the lines, turn them all into upper/lowercase and even eval some code while leaving it's result as the output.

    This is what I call a useful toolbox..