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

line breaks on Win32::Clipboard

by fbinard (Beadle)
on Sep 15, 2005 at 13:44 UTC ( [id://492213]=perlquestion: print w/replies, xml ) Need Help??

fbinard has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am writing a helper script whose out I want to place on the windows clipboard. Something like:
$SomeVar=<<TOHERE; line some other line some distinct yet similar line the daughter of line 0 and line 1 the line she loves even while being with line 2 TOHERE use Win32::Clipboard; Win32::Clipboard::Set($SomeVar);
However, when I do this, I lose my line breaks. Anyone's got a quick fix ?

Replies are listed 'Best First'.
Re: line breaks on Win32::Clipboard
by chester (Hermit) on Sep 15, 2005 at 13:58 UTC
    Try this:

    use warnings; use strict; use Win32::Clipboard; my $SomeVar=<<TOHERE; line some other line some distinct yet similar line the daughter of line 0 and line 1 the line she loves even while being with line 2 TOHERE $SomeVar =~ s/\n/\r\n/g; Win32::Clipboard::Set($SomeVar);

      It works, but it may not be portable between the various Win32 versions of Perl. "\n" can mean different things to differing perls. Best to use the literals (chars 0x0D and 0xOA are CR and LF, respectively). Also, you'll want not to replace line endings that are already correct, because you'd end up with a "\r\r\n" (bad).

      $SomeVar =~ s{(?<!\x0D)\x0A}{\x0D\x0A}g;

      Updates:

      • 2005-09.Sep-15 : Clarified term 'portable'

      <-radiant.matrix->
      Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
      The Code that can be seen is not the true Code
      "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: line breaks on Win32::Clipboard
by svenXY (Deacon) on Sep 15, 2005 at 14:13 UTC
    Hi,
    while ++chesters suggestion will certainly help, I tried it here on my vmware win2k and your code works fine. I pasted it into wordpad and code_genie (the latter switched to Windows style linebreaks) and both give me the string with breaks...
    Regards,
    svenXY
      Some programs are apparently smart enough to figure it out. vim for example. Wordpad works for me too, yep. Notepad displays an ASCII box instead. God only knows.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://492213]
Approved by socketdave
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found