Forum: Ruby Re: Ruby equivalent to simple awk program

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
397f61cc4458e13157b4facf72325e5f?d=identicon&s=25 Gennady Bystritsky (Guest)
on 2006-05-04 18:02
(Received via mailing list)
$ ruby -e 'puts $ARGF.readlines.reverse'

Gennady.
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-04 18:57
(Received via mailing list)
On May 4, 2006, at 11:59 AM, Gennady Bystritsky wrote:

>  $ ruby -e 'puts $ARGF.readlines.reverse'
>
> Gennady.

Someone didn't test their code ;) (It's ARGF not $ARGF)
51a34236538906ab994cf9f2e533d14d?d=identicon&s=25 Lou Scoras (ljscoras)
on 2006-05-04 22:15
(Received via mailing list)
> If you find yourself trying Perl before Ruby, however, seek
> psychiatric help immediately :)

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
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2006-05-04 22:21
(Received via mailing list)
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 Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
51a34236538906ab994cf9f2e533d14d?d=identicon&s=25 Lou Scoras (ljscoras)
on 2006-05-04 22:48
(Received via mailing list)
> 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.
D84df7c68f790e492c4ad4ec5fe65547?d=identicon&s=25 Florian Frank (Guest)
on 2006-05-04 23:10
(Received via mailing list)
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.
63e5a5c299c29f41a55bb6cab0153230?d=identicon&s=25 unknown (Guest)
on 2006-05-05 19:35
(Received via mailing list)
> ruby -e '$><<[*$<].reverse'

A great big +1 for that one :)  Just to prove that ruby can be every
bit as ugly (shows flexibility, right?) as any other language :)
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-05-05 20:16
(Received via mailing list)
tsuraan@tsuraan.net wrote:
>> ruby -e '$><<[*$<].reverse'
>
>
> A great big +1 for that one :)  Just to prove that ruby can be every bit
> as ugly (shows flexibility, right?) as any other language :)
I initially misread that as:

   ruby -e '$><<[*$<].perverse'

which seems somehow *far* more appropriate...
This topic is locked and can not be replied to.