Monday, 15 February 2010

Couldn't understand the Ruby command-line switch -0digit -



Couldn't understand the Ruby command-line switch -0digit -

from doc

-0digit =>

specifies input record separator ($/) octal number. if no digits given, null character separator. other switches may follow digits. -00 turns ruby paragraph mode. -0777 makes ruby read whole file @ 1 time single string, since there no legal character value.

my bad! couldn't digest @ all. let's started play it.

c:\>ruby -0777 -e 'a= gets; puts ' hi, ram. help me here? ^z #~~~> pressed come in here after ctrl+z , got output below- hi, ram. help me here? c:\>ruby #~~~> homecoming prompt c:\>ruby -000 -e 'a= gets; puts ' hi, ram. help me here? ^z #~~~> pressed come in here after ctrl+z , got output below- hi, ram. help me here? c:\>ruby #~~~> homecoming prompt c:\>ruby -00 -e 'a= gets; puts ' hi, ram. help me here? #~~~> pressed come in #~~~> pressed come in here , got output below- hi, ram. help me here? c:\>ruby #~~~> homecoming prompt

question: 1 - can set such octal or $/ below ?

carraige homecoming (\r) tab (\t)

if so, can have 1 illustration each see behaviours?

question: 2 - tried print value of "$/" , nil printed. how should see that?

c:\>ruby -00 -e 'a= gets; puts ;puts "here is: #{$/}"' hi hi here is: c:\>ruby -0777 -e 'a= gets; puts ;puts "here is: #{$/}"' hey! arjun going school? ^z hey! arjun going school? here is: c:\>

from using as

finally found out way how set the carraige homecoming (\r) , tab (\t).

find below code:

c:\>ruby -00 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hi hi here is: "\n\n" c:\>ruby -015 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hi hi ^z hi hi here is: "\r" c:\>ruby -011 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hello ^z hello here is: "\t" c:\>

finally print .inspect below :

c:\>ruby -00 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hi hi here is: "\n\n" c:\>

want share whole day's ruby : :)

from above link : ascii code

i got octal code of many more escape characters , played them ruby command line -0<digit> option:

here total list of example.. read , digest it. :)

@ubuntu:~$ ruby -010 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' spoon. need it.^h spoon. need it. here is: "\b" @ubuntu:~$ ruby -033 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hi..how you? going ^[ school today? hi..how you? going here is: "\e" @ubuntu:~$ ruby -011 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' today hot outside room today hot outside here is: "\t" @ubuntu:~$ ruby -015 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' mad?hey..^mhello..i telling dude... mad?hey.. here is: "\r" @ubuntu:~$ ruby -012 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' there? there? here is: "\n" @ubuntu:~$ ruby -040 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' iammmmmmmmmm iammmmmmmmmm here is: " " @ubuntu:~$ ruby -014 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' earth planet.remember it...^l dear brother earth planet.remember it... here is: "\f" @ubuntu:~$ ruby -000 -e 'a= gets; puts ;puts "here is: #{$/.inspect}"' hiiiii............ hiiiii............ here is: "\n\n" @ubuntu:~$

ruby ruby-1.9.3

No comments:

Post a Comment