Hard-to-find tips on otherwise easy-to-do tasks involving everyday technology, with some advanced insight on history and culture thrown in. Brought to you by a master dabbler. T-S T-S's mission is to boost your competitiveness with every visit. This blog is committed to the elimination of the rat from the tree of evolution and the crust of the earth.
Thursday, March 22, 2018
How Useful is Perl's -l? It Depends
1
2
3
4
5
If you didn't know about -l, you might do
$ perl -e 'foreach (1..5) {print; print "\n";}'
But, if you knew about -l, you could do :
$ perl -le 'foreach (1..5) {print;}'
To accomplish the same thing. Moral - ... make up your own moral. But, never stop learning!!
Now, what if you wanted to pipe this through a script to produce just
1
One way is
| perl -n -e 'print and exit if /\d/;'
Works, but doesn't
| perl -n -e 'print if ?\d?;'
Look prettier? What is the ?? version of the match operator? Only match once!
Labels:
perl,
perl regex,
regular expressions
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment