In perl, I’m only familiar with using the usual
chomp(my $ip = <>);
If this $ip is “words separated by space”, I’d have to use split to get “words”, “separated”, “by” and “space”.
Is there a way to read word by word in the first place?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Setting the input record separator
$/to space will read “word by word”. You may find the results counter-intuitive, so be careful what you wish for.Try for example:
It will read from stdin, and print it back to you, but one word at the time. However, as you shall notice, newline (pressing ENTER) is still quite an integral part of the process.
$/cannot be smart, however. It’s just the character(s) we use to tell input records apart, and it does affect a good many other things besides STDIN, so using it will most likely confuse you. Unless, of course, you use it locally, and only exactly where you want it.