f



gets gets

I'm a little surprised at this.
In irb, I tried puts gets gets.
Why? I don't know.
but basically, gets gets, seems to almost act like a heredoc!
myString = gets gets
puts myString

0
3/26/2007 8:17:49 AM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

2 Replies
1792 Views

Similar Articles

[PageSpeed] 4

On Mar 26, 2007, at 3:17 AM, John Joyce wrote:

> I'm a little surprised at this.
> In irb, I tried puts gets gets.
> Why? I don't know.
> but basically, gets gets, seems to almost act like a heredoc!
> myString = gets gets
> puts myString

It's not surprising at all.  First, let's insert the parentheses so  
we can see it as Ruby does:

   puts(gets(gets()))

Now we see that the right-most gets() call must be resolved first.   
Assuming you enter the String "END", that will be passed to the left- 
most gets() call as a parameter.

The parameter to gets() is an input record divider, so it will read  
ahead until it encounters "END" instead of the traditional "\n".   
This is the heredoc-like behavior you are seeing.

The result of the second gets() is then printed by puts().

Hope that explains what you are seeing.

James Edward Gray II


0
james8284 (4405)
3/26/2007 3:24:56 PM
Excellent explanation!
Perfectly clear.

On Mar 27, 2007, at 12:24 AM, James Edward Gray II wrote:

> On Mar 26, 2007, at 3:17 AM, John Joyce wrote:
>
>> I'm a little surprised at this.
>> In irb, I tried puts gets gets.
>> Why? I don't know.
>> but basically, gets gets, seems to almost act like a heredoc!
>> myString = gets gets
>> puts myString
>
> It's not surprising at all.  First, let's insert the parentheses so  
> we can see it as Ruby does:
>
>   puts(gets(gets()))
>
> Now we see that the right-most gets() call must be resolved first.   
> Assuming you enter the String "END", that will be passed to the  
> left-most gets() call as a parameter.
>
> The parameter to gets() is an input record divider, so it will read  
> ahead until it encounters "END" instead of the traditional "\n".   
> This is the heredoc-like behavior you are seeing.
>
> The result of the second gets() is then printed by puts().
>
> Hope that explains what you are seeing.
>
> James Edward Gray II
>
>


0
3/26/2007 4:00:53 PM
Reply:

Similar Artilces:

how to get newline with gets?
Hello. I like the -nonewline option of puts, and wonder why there isn't a counter option in gets? The reason I need it is effectively I am doing this: set line [gets -withnewline stdin] if {[lindex $line end] eq "\r" } { # do something } if {[lindex $line end] eq "\n" } { # do something different } I guess without such an option I have to read byte-by-byte to achieve this, right? Thanks. On 5/11/11 1:21 PM, =E5=90=95=E9=9F=A6=E7=94=AB wrote: > Hello. I like the -nonewline option of puts, and wonder why there isn't= a > counter option in gets? &g...

getting a warning about gets
I'm getting a warning on my linux gcc compiler: /tmp/ccXgHa9s.o(.text+0x48): In function `main': : warning: the `gets' function is dangerous and should not be used. And here's where I used gets: #include "common.h" //common.h includes string.h .... .... int main(void) { char zf_name[50]; .... printf("Enter the name of the file\n"); gets(zf_name); ... return 0; } On May 19, 10:38=A0am, pereges <Brol...@gmail.com> wrote: > I'm getting a warning on my linux gcc compiler: > > /tmp/ccXgHa9s.o(.text+0x48): In function ...

Return of gets gets
Not long ago I posted about gets gets I said it acted a bit like a Heredoc. I've since realized that it is actually more similar to readlines In fact, it behaves identically thus far. example: irb(main):004:0> lines = readlines ff fff akenll329 \n kls => ["ff\n", "fff\n", "akenll329\n", "\\n\n", "kls\n"] irb(main):005:0> puts lines ff fff akenll329 \n kls => nil irb(main):006:0> lines = gets gets fff ff ahoy \n lll ll => "ff\nahoy\n\\n\nlll ll\n" irb(main):007:0> puts lines ff ahoy \n lll ll => nil No...

ruby-lang emails getting blocked
It seems that beryllium.ruby-lang.org has found itself on spamcop's blocking list (which explains why I haven't gotten any mails in about 15 hours): http://www.spamcop.net/bl.shtml?210.163.138.100 Caleb On Wednesday 15 February 2006 05:06 am, Caleb Tennis wrote: > http://www.spamcop.net/bl.shtml?210.163.138.100 http://www.spamcop.net/w3m?action=blcheck&ip=210.163.138.100 I don't understand, unless someone was using a faked address and actually hit one of the spam traps, how could this happen? Tsume ...

[News] Ruby Gets Roadmap, Qt 4.7 Gets New Features
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ruby 1.9.2 expected in August ,----[ Quote ] | According to a new schedule, the next version of | the dynamic Ruby 1.9.2 scripting language will | probably be released in mid August. While | previous plans were for a final release by last | December, the developers wanted to ensure that | the new version passed the RubySpec tests. | Eventually this lead to the release being | postponed. Ruby 1.9.2dev has now passed all the | relevant tests. `---- http://www.h-online.com/open/news/item/Ruby-1-9-2-expected-in-August-956866.html Qt 4.7 deb...

Get(RecordNumber) = Get(RecordID)
Tried removing all indexing from all fields in my table but to no avail...the equation in the subject persists. Using Advanced 10.0v1. Any clues? I need the record number in the current (sorted) found set to be the value in a calculation (number) field. How is this done? TIA, Tim On Jun 19, 10:53=A0am, tim <tim.ruc...@gmail.com> wrote: > Tried removing all indexing from all fields in my table but to no > avail...the equation in the subject persists. =A0Using Advanced 10.0v1. > > Any clues? =A0I need the record number in the current (sorted) found set > to be the val...

Get a Linux. Get a Mint!
https://www.youtube.com/watch?v=aufL76bXLAg ...

get we get a fire started?
Hey all slow here these days....... A simple question for the gurus.........can I get hypervoxels to show up behind a transparent object? for example......bubbles inside a glass....shot from outside the glass........or are you forced to render the hypervoxels first and then overlay the glass later? I am stuck still using LW8.5 all thoughts welcome....just to get some discussion going hope everyone is well cheers Matthew ...

GET, GET# and end of files
This is something I tripped over yesterday. Many of my BASIC programs have the following structure: 10 open source and target files 100 clear buffer contents 200 input from a source file, process and store data in the buffer The above step is repeated while space in the buffer is available 300 output data to a target file when the buffer is full. continue at lines 100 to 300 until all data in the source file has been processed. 400 endjob processing when an end of the source file is detected. Most programmers begin line 200 with code that looks like ...

Getting parameters from the get method
Hello, I am pretty rusty with javascript and I am trying to make a webpage that will basically act as a wrapper from one webpage to another. What I mean by this is that I will hit this page like: webpage.htm?Param1=... and I will take the passed params and post them to another page. I have the post part working, but I was just wondering how I can use just Javascript and read those values passed to this webpage. Is this even possible? Thanks for all of your time. Matt "Matt" wrote > Hello, > > I am pretty rusty with javascript and I am trying to make a webpage > ...

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

difference between chan gets / gets
Hi ! What difference between command chan gets and gets, chan puts and puts ? Many thanks ! serge_darin@mail.ru <serge_darin@mail.ru> wrote: > What difference between command chan gets and gets, chan puts and > puts ? They are supposed to be the same. puts is here for compatibility (and for those too lazy to write those extra 5 chars, like me), whereas chan is an attempt to have related functionality together in a single command. If you're old to tcl, you'll likely be used to top-level "puts", whereas if you're new to tcl, you're more likely to memo...

Getting Ruby
Given that Debian and UBUNTU break ruby up into a multitude of sub installs, I think the comment below from http://www.ruby-lang.org/en/downloads/ can be misleading to new users. However, on some platforms, there are package management solutions that make installing Ruby extremely easy. For example, on Debian or Ubuntu apt-get provides an easy and elegant solution: % sudo apt-get install ruby irb rdoc For irb and rdoc you will need to enable the universe repository. Many people will not read the description where it s...

gets in ruby
I'm a newbie in Ruby. And, after a first couple of tutorials, I came across the function 'gets'. Being similar to the function in C, I was wondering if this would expose programs written in Ruby to buffer overflow vulnerabilities? Or am I overlooking something here that would invalidate such an argument? I mean, does the 'gets' in ruby perform bounds checking? -- _ _ _]{5pitph!r3}[_ _ _ __________________________________________________ “I'm smart enough to know that I'm dumb.” - Richard P Feynman On Dec 22, 2006, at 24:25, Spitfire wrote: > I'm a...

Web resources about - gets gets - comp.lang.ruby

THE SOCIALIST MILLIONAIRE: Financial Scandals Trail the Loathsome Communist-Lover Bernie Sanders
By Cliff Kincaid Responding to one of Anderson Cooper’s softball questions, socialist Bernie Sanders (I-VT) told the CNN Town Hall on Wednesday ...

Taiwan Earthquake: Was Faulty Construction The Reason Why The Wei-Guan Golden Dragon Building Collapsed ...
Questions are being raised why the Wei-guan Golden Dragon Building would crumble and fall, while other buildings in the area remained standing. ...

Turkey at capacity as refugees flee Russian bombardment of Aleppo
USA TODAY Turkey at capacity as refugees flee Russian bombardment of Aleppo USA TODAY With Russian airstrikes intensifying on the Syrian-rebel ...

‘Red Dead Redemption’ And More Added To Xbox One Backwards Compatibility
Another batch of not-yet-officially released backwards compatible titles for the Xbox One were discovered over the weekend. Rockstar Games’ title ...

Twitter CEO Responds To Timeline Controversy
Earlier this week it was reported that Twitter will soon make a significant change to timelines that will actually make the microblogging network ...

Alejandro G. Iñárritu & Alex Garland Win 2016 Directors Guild Awards
This is an awards season unlike any other. Last night, the 68th DGA Awards were held in Los Angeles and for the second year in a row, Alejandro ...

GST hike not in Turnbull Government's tax reform plans, ministers say
Federal Government ministers say the Coalition has abandoned the idea of lifting GST, but its tax plans may still contain some bold ideas.

Tory grassroots' fury over David Cameron jibe is 'understandable, says rising star MP James Cleverly
James Cleverly, Conservative MP for Braintree, said: 'I can understand why that has ruffled feathers'

Mark Zuckerberg Speaks Mandarin For Chinese New Year, Gets 18 Million Views On Facebook
Facebook CEO Mark Zuckerberg is a man of many talents. A new video titled “ Happy New Year! ” on Facebook, posted by Mark Zuckerberg on Saturday, ...

Colombia says 3,177 pregnant women have Zika virus, but no birth defects, yet
Colombia's President Juan Manuel Santos said Saturday that there's no evidence Zika has caused any cases of the birth defect known as microcephaly ...

Resources last updated: 2/7/2016 9:48:51 PM