4 ms·
I've been learning this at work as part of a get-good-at-Linux regime :) One of the most surprising things for me is that as horrible to a beginner that some of
by mcintyre1994 10y ago
I've been learning this at work as part of a get-good-at-Linux regime :) One of the most surprising things for me is that as horrible to a beginner that some of the one liners in the command line can look, it's actually quite a forgiving scripting language. I don't think I've seen another language where you can increment a variable without declaring/initialising it, nor where you can set indices on an array without it being declared (except in a constructor fashion I guess).
- tyingq 10y agoPerl does those things if you don't "use strict;" $ perl -e '++$i && print $i;$foo[2]=99;$foo[1]=88;for (@foo) {print}' 18899
- mcintyre1994 10y agoThanks for pointing that out! I haven't used perl yet, it should probably be on my list of things to learn though :)
- tyingq 10y agoA fair amount of it is based on awk, so awk might be better to start with.
- throwaway7645 10y agoPerl5 is a really big language...especially when you look at extending it with the 10 gigs of CPAN code. It grew from a need to have a better Awk, but I'm not sure if they're related close enough for starting with Awk to matter. Perl6 is an all around sister language that isn't ready for production yet, but has a ton of power and features including the ability to call other languages (python, perl5, Lua, scheme).
- tyingq 10y agoSure. I meant that though in the context of "I've been learning this at work as part of a get-good-at-Linux regime". Which I suppose involves using awk mostly for command pipelines / one liners. Awk and Perl would have a lot of overlap (autosplit, matching, BEGIN, END, etc) in that space.
- throwaway7645 10y agoYea, if you're just doing one-liners...probably easier to start with Awk. For more complicated scripts, Perl or Python should be built in.
- int_19h 10y agoBASIC (the traditional dialects thereof, anyway) does all of those things. In fact, you can even read indices of an array without declaring it. If you do, it's auto-declared as having 11 elements (with indices 0 to 10), filled with zeroes. This was still supported as late as VB for DOS. I wouldn't be surprised if VB6 also had this behavior.