Remix.run Logo
vidarh 10 hours ago

> I'd never use because I wouldn't have the faintest idea what $F[1] would do.

I don't use it often either, and most people probably don't know about it. But $F will contain each row of the input split by the field separator, which you can set with -F, hence the comparison to Awk.

Basically, each of -n, -p, -a, -F conceptually just does some simple transforms to your code:

-n: wrap "while gets; <your code>; end around your code and call the BEGIN and END blocks.

-a: Insert $F = $_.split at the start of the while loop from a. $_ contains the last line read by gets.

-p: Insert the same loop as -n, but add "puts $_" at the end of the while loop.

These are sort-of inherited from Perl. like a lot of Ruby's sigils, hence my mention of it (I agree its ugly). They're not that much harder to remember than Awk, and it saves me from having to use a language I use so rarely that I invariably end up reading the manual every time I need more than the most basic expressions.

> I understand this but still reject it; I try to use the tool that is best.

I do too, but sometimes you need to access servers you can't install stuff on.

Like you I have lots of my own Ruby scripts (and a Ruby WM, a Ruby editor, a Ruby terminal emulator, a file manager, a shell; I'm turning into a bit of a zealot in my old age...) and much prefer them when I can.