It happened to me again. I though I was going to work out a small shortcut on the text interface command line (shell) and it would take me perhaps a couple of minutes. Instead, it became an extreme detour over two days of effort and I must have put at least 2 or 3 hours into it. In the end, the answer was "perl". So here's what happened.

BTW, I'd first thought to create this node in "Cool Uses For Perl" but there's something HTML-ish messing up the layout there. The page horizontal width is massively enlarged so that one has to scroll drastically to read nodes.

Good monks (nuns too), here's how it started. I had a snippet of data copied from a metacpan.org web page into the system clipboard. Here's the data:


   CPAN::Meta
   ExtUtils::Builder
   ExtUtils::Builder::Compiler
   ExtUtils::Config
   ExtUtils::Helpers
   ExtUtils::InstallPaths
   Getopt::Long
   List::Util
   TAP::Harness

What I wanted was the transmogrification of this list of lines into a single line (spaces between module names, of course). What I then planned to do with with my string data (again, we're in the shell here) was to run cpanminus on the list, which btw are dependencies of the module Dist::Build, so that I'd be ready to install Dist::Build without having cpanm have to do the depends-on dance for me. Why would want to do that? Sometimes I want to open a shell in a module build dir and build by hand, for a few different reasons. In this case the goal of shaping that string of module names completely eclipsed the original intention. It became an obsession.

Here's how it unfolded. I went to the toolshed and first I grabbed the hoe (sed). I do things on the principle of finding the smallest, simplest tool to do the jobs, it's just a matter of personal preference to be that way. sed doesn't weight that much.

I don't have a record to show the reader, of exactly what my invocation of sed looked like, because I had an os crash/reboot that wiped out the bash history before it could be saved, but the result I eventually got looked like this:

TAP::HarnessstallPathspiler

I should note that sed scripts can become very elaborate and I am not now (and probably never was) a skilled sed user; I generally just find a matching or substitution expression that will accomplish what I want, and that's as far as it goes. I found some very elaborate sed scripting on Snark-Overflow that didn't work for me. I was starting to feel cursed.

If anyone can explain to me why I get that string, I'll be very satisfied.

Next I put the hoe back and grabbed the spade (tr). Once I read the help page for tr I worked out a command line, and what did I get?

TAP::HarnessstallPathspiler

That's right. The same damned mojibake mess.

The same when I went to the toolshed once more and selected the pitchfork (fmt). I'm not sure whether I've ever even used fmt before, I dutifully read the help page and tried. Aughhhhh. More mojibake.

OK, it's Perlmonks here and so you saw this coming: I put away the hand tools and rolled out the backhoe (perl). Now, I flatter myself that I know perl better than I know sed or fmt, and I wondered why it had taken me so long to turn to our finest data-munger.

Well, I still had the dreadful line at first,with perl (which was a little bit of a comfort because I had long since started to question my own sanity):

TAP::HarnessstallPathspiler

Here's one thing I tried with perl:

$ </dev/clipboard perl -e 'push @a,$_ while <>;chomp @a;print join(@a,q[ ])'

Yep, same thing. But at last, I found the/a perl solution.

$  </dev/clipboard perl -0777 -e 'my ($l)=<>; $l=~s{.\cJ}[ ]g; print $l;'
OUTPUT:
CPAN::Meta ExtUtils::Builder ExtUtils::Builder::Compiler ExtUtils::Config ExtUtils::Helpers ExtUtils::InstallPaths Getopt::Long List::Util TAP::Harness

The obscure -0777 switch in that invocation turns on slurp mode so every line gets read at once, to the end of file.

The observant reader is perhaps wondering what's this /dev/clipboard. I'm working on Cygwin; that's a special device file that Cygwin makes available, that's all.

If there's a lesson to be learned here, it might be "use the tool you know best, first."

Thanks for reading, and I know some of you laughed in rueful recognition (because this sort of thing has happened to me before this time, too).

Dec 26, 2025 at 20:47 UTC

A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)

Replies are listed 'Best First'.
Re: A Christmas detour: it's the simplest damn things that bite us sometimes
by choroba (Cardinal) on Dec 26, 2025 at 23:09 UTC
    > use the tool you know best, first.

    Let me teach you another lesson here, equally important. If the output is weird, check the input.

    You mention cygwin, which adds some hints. The input contains MSWin32 EOL characters, so xxd shows it as

    00000000: 4350 414e 3a3a 4d65 7461 0d0a 4578 7455 CPAN::Meta..ExtU 00000010: 7469 6c73 3a3a 4275 696c 6465 720d 0a45 tils::Builder..E 00000020: 7874 5574 696c 733a 3a42 7569 6c64 6572 xtUtils::Builder 00000030: 3a3a 436f 6d70 696c 6572 0d0a 4578 7455 ::Compiler..ExtU 00000040: 7469 6c73 3a3a 436f 6e66 6967 0d0a 4578 tils::Config..Ex 00000050: 7455 7469 6c73 3a3a 4865 6c70 6572 730d tUtils::Helpers. 00000060: 0a45 7874 5574 696c 733a 3a49 6e73 7461 .ExtUtils::Insta 00000070: 6c6c 5061 7468 730d 0a47 6574 6f70 743a llPaths..Getopt: 00000080: 3a4c 6f6e 670d 0a4c 6973 743a 3a55 7469 :Long..List::Uti 00000090: 6c0d 0a54 4150 3a3a 4861 726e 6573 730d l..TAP::Harness. 000000a0: 0a .

    Do you see those 0d bytes? Strawberry Perl (or any other perl compiled on MSWin) would recognise them, but cygwin Perl is of the *nix kind, so it expects 0a only.

    The output you got was not exactly what you thought. The newlines were correctly replaced by spaces, but the carriage returns remained in the data, causing the cursor to return left and overwrite the text again and again.

    tr '\n' ' ' < input| xxd 00000000: 4350 414e 3a3a 4d65 7461 0d20 4578 7455 CPAN::Meta. ExtU 00000010: 7469 6c73 3a3a 4275 696c 6465 720d 2045 tils::Builder. E ...

    You see? We have 20 (the space) there, but it's preceded by 0d.

    What would I use? Any of the following:

    perl -pe 'tr/\n\r/ /d' perl -pe 's/\s+/ /' tr -s '\n\r' ' '

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: A Christmas detour: it's the simplest damn things that bite us sometimes
by talexb (Chancellor) on Dec 27, 2025 at 18:58 UTC
      The observant reader is perhaps wondering what's this /dev/clipboard. I'm working on Cygwin; that's a special device file that Cygwin makes available, that's all.

    Well, Today I Learned about a neat feature of Cygwin's command line shell. I just looked in my /dev directory (under Ubuntu) and didn't find /dev/clipboard .. but for Linux, that would probably be better implemented as something under ~ (the current user's home directory), for security reasons.

    Oh no. Another idea for a cool project. :/

    Alex / talexb / Toronto

    As of June 2025, Groklaw is back! This site was a really valuable resource in the now ancient fight between SCO and Linux. As it turned out, SCO was all hat and no cattle.Thanks to PJ for all her work, we owe her so much. RIP -- 2003 to 2013.