开发者

How to make a standard Unix Filter using Ruby?

开发者 https://www.devze.com 2023-04-10 03:11 出处:网络
I found this ruby problem on RubyQuiz, which states besides the problem itself, the following: \"The script should be a standard Unix filter, reading from files

I found this ruby problem on RubyQuiz, which states besides the problem itself, the following:

"The script should be a standard Unix filter, reading from files specified on the command-line or STDIN and writing to STDOUT. Each line of input will contain one integer (between 1 and 3999) expressed as an Arabic or Roman numeral"

I have no idea how to do a Unix Filter using Ruby.. to read files in this case,

Could somebody please enlighten me on how to accomplish this task in the best way p开发者_开发技巧ossible.

Thanks as always!


The best way to read files from STDIN is using ARGF, as explained in this answer: Best practices with STDIN in Ruby?

You can write to STDOUT using puts or printf.

For more detailed info about IO in Ruby, read the Ruby Doc: http://www.ruby-doc.org/core/classes/IO.html

0

精彩评论

暂无评论...
验证码 换一张
取 消