How do i enter the in data ?

Add a reply

Posted by christer 791 days ago:
is it command line or readline?
Please give an example, I can't make this work!
Posted by will 789 days ago:
Your data is available via stdin, eg:

echo "Hello World" | ruby -e"puts STDIN.read"

To achieve this same result in codegolf your program would just be:

puts STDIN.read
Posted by rretzbach 787 days ago:
Since the main topic here is golfing I advice to use ARGF or $< instead of STDIN.
Posted by marmalade 785 days ago:
Since the main topic here is golfing I advice to use ARGF or $< instead of STDIN.

echo 'hello world' | ruby -e'puts$<.read'

works assuming $* is empty.

i agree that some challanges should use argv instead.
Posted by dfg59 780 days ago:
Since the main topic here is golfing I advice to use ARGF or $< instead of STDIN.

If the challenge calls for reading in multiple lines, is there a more concise way of doing the following:

a,b = readlines;

Thanks for the help.
Posted by carldr 778 days ago:
Not really, although I would suggest that making use of the fact that calling gets sets $_ to the text that was read and some other methods in Kernel operate on $_ could save you a few bytes.
Posted by SilentGeneration 553 days ago:
I was just wondering how one would test something like (using the basic example):

puts STDIN.read

?
Posted by SilentGeneration 552 days ago:
I was just wondering how one would test something like (using the basic example):

puts STDIN.read

?

Never mind, I got it.

Add a reply