in reply to One-liner to append text at fixed column
Fiddling around a bit, trying to find a solution where it becomes more clear what is being searched for and which characters are being replaced. But still, it is not very pretty.
$_ = "abc_something" ; print $_ . "\n" if /abc/ && substr( $_, 0, 4 ) =~ s/(.+)/" "x((length $1)+2)."#:"/e ;
The substr just takes care of replacing the first part with " #:". Make sure that the search for 'abc' is done before doing the replacement since it is greedy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: One-liner to append text at fixed column
by LanX (Saint) on Nov 16, 2018 at 13:29 UTC | |
by Veltro (Hermit) on Nov 16, 2018 at 15:31 UTC | |
by LanX (Saint) on Nov 16, 2018 at 15:55 UTC |