[nSLUG] Any Perl Experience around?

Vlado Keselj vlado at dnlp.ca
Thu Jun 22 15:40:53 ADT 2017


Hi,

I would say that

perl -lne 's/(.{34}).*/$1... /s; print'

simply cuts off too long lines.  If a line has 34 characters or more, it
keeps the first 34 characters and adds '...'.

-l effectively removes the newline character from every line before
processing, and adds it back just before printing.

-n creates an implicit loop while(<>){...} around the code.  Actually, in
this case I think it would be better to use -p and loose the final
'print'.

-e is just an expression in the command line; i.e., a small program in
command line rather than reading a program file.

The final '/s' is a regular expression option to treat the whole string as
a single line in case of a multi-line string, but it seems to be redundant
since the string is always a single line.

The code adds "..." even if the line is exactly 34 characters long, which
seems to be a minor bug.  The following line would likely be better:

perl -lpe 's/(.{34}).+/$1... /'

Since the main problem with color is that 'column -x' cannot deal with it,
it looks very painful to force it through this command.  I would rather
write the whole thing in Perl.


Regards,
Vlado

On Thu, 22 Jun 2017, Hatem Nassrat wrote:

>
>
> Hatem Nassrat
>
> On Wed, Jun 21, 2017 at 9:54 PM, Hatem Nassrat <hnassrat at gmail.com> wrote:
>       The switches to perl -lne mean something, not sure off the top, but I think -e is for
>       extending regex expressions. The rest may have something to do with processing escape
>       characters, not sure.
>
>
> This is totally wrong, thats not what the switches mean. -e is for expression (do'h) and -n loops over
> the input (I think, not sure still) and -l is hard for me to understand let alone explain so here is
> the text:
>
> -l[octnum]
>
> enables automatic line-ending processing. It has two separate effects. First, it automatically
> chomps $/ (the input record separator) when used with -n or -p. Second, it assigns $\ (the output
> record separator) to have the value of octnum so that any print statements will have that separator
> added back on. If octnum is omitted, sets $\ to the current value of $/
>
>  . For instance, to trim lines to 80 columns:
>
> I will try something out if it works will send you the regex. 
>
>
-------------- next part --------------
_______________________________________________
nSLUG mailing list
nSLUG at nslug.ns.ca
http://nslug.ns.ca/mailman/listinfo/nslug


More information about the nSLUG mailing list