A fuller explanation.
Windows text files store returns as a combination of two
characters, character 13 then 10. (Which is conveniently represented as "\r\n" on that platform.) Perl is from Unix, which is used to using a single character, character 10 (ie "\n") for a line ending. For the sake of portability, Perl does this conversion by default when reading or writing files (you can use binmode to turn this conversion off). However the Win32::Clipboard module does not do this conversion.
Therefore returns in Windows come in through the clipboard as "\r\n". And many programs will want to see them come back as "\r\n" as well. Some can work around it, but others cannot. If doing this escaping yourself sounds like too much of a bother, you can do this:
# Like Get but handles incoming returns
sub Win32::Clipboard::GetEsc {
my $self = shift;
my $text = shift;
$text =~ s/\r\n?/\n/g;
$self->Get($text);
}
# Like Set but escapes outgoing returns.
sub Win32::Clipboard::SetEsc {
my $self = shift;
my $text = shift;
$text =~ s/\r\n?|\n/\r\n/g;
$self->Set($text);
}
After putting that that bit of code in your program you can GetEsc and SetEsc and things
will Work As Expected. (Feel free to edit your own copy of Win32::Clipboard to add these functions. If you do that, then you don't need to include Win::Clipboard:: in the names. See the package command to learn why not.) |