Re: Ruby equivalent to simple awk program


#1

$ ruby -e ‘puts $ARGF.readlines.reverse’

Gennady.


#2

On May 4, 2006, at 11:59 AM, Gennady B. wrote:

$ ruby -e ‘puts $ARGF.readlines.reverse’

Gennady.

Someone didn’t test their code :wink: (It’s ARGF not $ARGF)


#3

If you find yourself trying Perl before Ruby, however, seek
psychiatric help immediately :slight_smile:

Sometimes you’ll find a machine that doesn’t have ruby installed.

Besides, it’s not that bad. Really I promise it won’t hurt a bit.

$ perl -ne 'push @a, $_; END { print reverse @a }'

It’s not any worse than the awk (but not a pretty as the ruby). Like
it was said before, use the tools you have:

$ tac test.rb

#4

On 4-May-06, at 4:14 PM, Louis J Scoras wrote:

it was said before, use the tools you have:
If you are going to resort to perl then you should probably use

$ perl -e ‘print reverse <>’

Mike

Mike S. removed_email_address@domain.invalid
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.


#5

If you are going to resort to perl then you should probably use

$ perl -e ‘print reverse <>’

Heh. Very true, that’s much better. I had awk on the brain.


#6

Louis J Scoras wrote:

If you are going to resort to perl then you should probably use

$ perl -e ‘print reverse <>’

Heh. Very true, that’s much better. I had awk on the brain.

ruby -e ‘$><<[*$<].reverse’

This looks like Perl is supposed to look, too.


#7

removed_email_address@domain.invalid wrote:

ruby -e ‘$><<[*$<].reverse’

A great big +1 for that one :slight_smile: Just to prove that ruby can be every bit
as ugly (shows flexibility, right?) as any other language :slight_smile:
I initially misread that as:

ruby -e ‘$><<[*$<].perverse’

which seems somehow far more appropriate…


#8

ruby -e ‘$><<[*$<].reverse’

A great big +1 for that one :slight_smile: Just to prove that ruby can be every
bit as ugly (shows flexibility, right?) as any other language :slight_smile: