From the doc
-0digit =>
specifies the input record separator ($/) as an octal number. If no digits given, the null character is the separator. Other switches may follow the digits. -00 turns Ruby into paragraph mode. -0777 makes Ruby read whole file at once as a single string, since there is no legal character with that value.
My bad! Couldn't digest it at all. So let's started to play with it.
C:\>ruby -0777 -e 'a= gets; puts a '
Hi, This is Ram.
Could you help me here?
^Z #~~~> pressed ENTER here after CTRL+Z and got the output as below-
Hi, This is Ram.
Could you help me here?
C:\>ruby #~~~> return the prompt
C:\>ruby -000 -e 'a= gets; puts a '
Hi, This is Ram.
Could you help me here?
^Z #~~~> pressed ENTER here after CTRL+Z and got the output as below-
Hi, This is Ram.
Could you help me here?
C:\>ruby #~~~> return the prompt
C:\>ruby -00 -e 'a= gets; puts a '
Hi, This is Ram.
Could you help me here? #~~~> pressed ENTER
#~~~> pressed ENTER here and got the output as below-
Hi, This is Ram.
Could you help me here?
C:\>ruby #~~~> return the prompt
Question: 1 - Can I set such octal
or $/
to as below ?
carraige return (\r)
tab (\t)
If so, Can I have one example for each to see their behaviours?
Question: 2 - I also tried to print the value of "$/"
and nothing printed. So how should I see that?
C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/}"'
hi
hi
here is:
C:\>ruby -0777 -e 'a= gets; puts a ;puts "here is: #{$/}"'
Hey! Arjun
Are you going school?
^Z
Hey! Arjun
Are you going school?
here is:
C:\>
From the Using as
Finally I found out the way about how to set the carraige return (\\r) and tab (\\t)
.
Find the below code:
C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hi
Hi
here is: "\n\n"
C:\>ruby -015 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
hi
hi
^Z
hi
hi
here is: "\r"
C:\>ruby -011 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hello
^Z
Hello
here is: "\t"
C:\>
Finally I could print with .inspect
as below :
C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hi
Hi
here is: "\n\n"
C:\>
Want to share my whole day's with ruby : :)
From the above link : ASCII Code
I got the octal code of many more escape characters and also played with them with Ruby command line -0<digit>
option:
Here is the full list of example.. read and digest it. :)
@ubuntu:~$ ruby -010 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
This is a spoon. Do you need it.^H
This is a spoon. Do you need it.
here is: "\b"
@ubuntu:~$ ruby -033 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hi..How are you?
Are you going ^[ school today?
Hi..How are you?
Are you going
here is: "\e"
@ubuntu:~$ ruby -011 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Today is very hot outside the room
Today is very hot outside
here is: "\t"
@ubuntu:~$ ruby -015 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Are you mad?hey..^Mhello..I am telling you dude...
Are you mad?hey..
here is: "\r"
@ubuntu:~$ ruby -012 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Are you there?
Are you there?
here is: "\n"
@ubuntu:~$ ruby -040 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Iammmmmmmmmm a
Iammmmmmmmmm
here is: " "
@ubuntu:~$ ruby -014 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Earth is an planet.Remember it...^L dear brother
Earth is an planet.Remember it...
here is: "\f"
@ubuntu:~$ ruby -000 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"'
Hiiiii............
Hiiiii............
here is: "\n\n"
@ubuntu:~$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.