4 ms·
The former ubiquity of Perl made most of these common knowledge. For example, $? works in both Perl and bash (actually, I don't know which did this first...). S
by wonnage 14y ago
The former ubiquity of Perl made most of these common knowledge. For example, $? works in both Perl and bash (actually, I don't know which did this first...). So in the context of shell scripts, where Ruby started, having these magic globals makes a lot of sense.
IMO they can make code easier to understand, once you've learned what they mean. $2 conveys the same idea as matches[2] without having to think about array indices, and why the matches aren't zero-indexed like a normal array. This is obviously totally subjective.