5 ms·
It's a lot easier to delete specific lines using sed. Also you can have sed do replacements to the n'th instance of something. Doing that in Perl is a bit more
by scdlbx 12y ago
It's a lot easier to delete specific lines using sed. Also you can have sed do replacements to the n'th instance of something. Doing that in Perl is a bit more complicated and a lot less succint.
$ echo "foo foo foo foo" | sed 's/foo/bar/3'
foo foo bar foo
- emmelaich 12y agodeleting (i.e) not printing lines Here are the examples for not printing the 4th line: sed: sed -n '4!p' awk: awk 'NR != 4' perl: perl -ne '$. != 4 && print' Not much between them really.
- scdlbx 12y agoI would consider 'sed 4d' to be significantly easier than doing the same in Perl, but I don't disagree that it's not that hard to do in either.
- raiph 12y agoThe Rakudo Perl 6 compiler is still immature and slow, and the -i option (in-place edit) hasn't yet been implemented, but, at least for comparison's sake: $ perl6 -pe 'next if ++$ == 2' example.txt ... prints all lines except line 2. This is an example from Perl 6 One Liners[1]. The `$` is just just an unnamed variable that is getting incremented once per evaluation (-e is for `evaluate`) which in this case happens once per line (-p is for printing each line of input after eval'ing the code -- unless a `next` applies, in which case that line gets skipped). And... $ echo "foo foo foo foo" | perl6 -pe 's:3rd/foo/bar/' ... replaces the third foo with bar. P6 regexes are far easier to read and way more powerful than P5 regexes. The `:3rd` bit is a general language feature called "Adverbs", in this case applied to the regex focused s/// built in.[2] [1] https://github.com/sillymoose/Perl6-One-Liners https://github.com/sillymoose/Perl6-One-Liners [2] http://doc.perl6.org/language/regexes#Adverbs http://doc.perl6.org/language/regexes#Adverbs
- cogburnd02 12y agoI've read literally nothing about perl 6 but what David Skoll wrote here: http://david.skoll.ca/blog/2010-07-29-perl-sss.html http://david.skoll.ca/blog/2010-07-29-perl-sss.html Quote: "I asked on a forum what the goals are for relative size and speed of Perl 6 vs. Perl 5, and a Perl 6 developer responded that a reasonable goal would be to have Perl 6 be twice as big as Perl 5 and take twice as long to start up. "To achieve this goal, the Perl 6 developers will have to shrink the program size by a factor of 6.1 (that is, get rid of about 84% of the code.) They'll need to reduce startup memory consumption by a factor of 13.7 (that is, cut out 93.7% of their memory use) and reduce startup time by a factor of over 275. "Oh, and this is after they add in all the missing features required to bring Perl 6 up to production-level." Has the situation gotten better since 2010?
- raiph 12y ago> Has the situation gotten better since 2010? Not really. Startup uses about the same RAM. It's about 10x faster. The best docs I know about performance would be http://pmichaud.com/2012/pres/yapcna-perflt/slides/slide17.html http://pmichaud.com/2012/pres/yapcna-perflt/slides/slide17.h... and http://jnthn.net/papers/2014-yapceu-performance.pdf#page=72 http://jnthn.net/papers/2014-yapceu-performance.pdf#page=72 > "... all the missing features required to bring Perl 6 up to production-level." The latest story is that the last major missing features (Unicode grapheme-by-default and native arrays) will land in the next few months and Perl 6 will be declared "officially ready for production use" by the end of 2015.