[nSLUG] Any Perl Experience around?

Joel Maxuel j.maxuel at gmail.com
Wed Jun 21 19:30:18 ADT 2017

Hi all,

I encountered this example script in a StackExchange question[1]:


What it does is truncates the results (by file/directory) of an ls
statement to organize in predictable columns.

It was not long before I thought, "why not have colour?"

So I made a quick addition, and regretted it the rest of the night:

ls -F --color | perl -lne 's/(.{24}).*/$1... /s ; print' | column -x

Why so?  Colour is made up of additional/escape characters which the
close-out gets truncated and can leave symbols on-screen.  So I started to
analyze the enclosed Perl.  I see that a substitution is used (find > n
chars, replace with truncated version + ".... "), but I don't understand
the inner workings.

Essentially, looks like I want to trim a result if it is n characters wide
and no \e char to be found, or if with an \e, trim within it (which looks
to be 8 extra chars to the left and 4 to the right).

This may be a regex thing.

Any ideas?  Thanks.


Joel Maxuel

"One should strive to achieve, not sit in bitter regret."
 - Ronan Harris / Mark Jackson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/pipermail/nslug/attachments/20170621/ba448bba/attachment.html>

More information about the nSLUG mailing list