3 ms·
> Filtering ... perl one-liners can be used for filtering lines matched by a regexp, similar to grep, sed and awk. In this section, the examples do stuff that
by jolmg 6y ago
> Filtering ... perl one-liners can be used for filtering lines matched by a regexp, similar to grep, sed and awk.
In this section, the examples do stuff that are easy to do with grep, sed, or awk, but since perl is more powerful, wouldn't it be better to use examples that aren't as easy to do with those other tools?
For example, I recently found I could use short perl one-liners to filter files in a pipe like using `[[ -f $file ]]` per line. I used to use stest from dmenu like this:
pacman -Qlq $pkg | stest -f
but now I see I could instead do the following anywhere without installing a special package:
pacman -Qlq $pkg | perl -lne 'print if -f'
- asicsp 6y ago>wouldn't it be better to use examples that aren't as easy to do with those other tools? hmm, food for thought...I wasn't thinking along those lines after I had shown/linked powerful one-liners in the very first section: https://learnbyexample.github.io/learn_perl_oneliners/one-liner-introduction.html#why-use-perl-for-one-liners https://learnbyexample.github.io/learn_perl_oneliners/one-li... I'll see if I can also add such examples in the actual content too. I was concentrating more on explaining the syntax, showing features, etc