Perl autosplit function with in-place editing

I just had a task when I needed to replace every third value in a separate file with a tab with a fixed value. I assume that this can be done in Perl in a Unix shell, for example,

$perl -a -n -i  -F'/\t/' -e '$F[2]="THE FIXED VALUE";print join "\t", @F' bla.txt

I just wanted to know if this is the โ€œrightโ€ way, or if itโ€™s better for it (so that there is no better definition at the moment)?

+3
source share
1 answer

I think your single line font is reasonable and readable. There are many more ways to do this. I would add perlrun parameters and save a few keystrokes:

perl -F'\t' -i -ape'$F[2]="THE FIXED VALUE"; $_ = join "\t", @F' bla.txt

Shame on $,not being filled with an argument -F, so there is still a snippet of repetition.

+3

Source: https://habr.com/ru/post/1792839/


All Articles