# How to ensure no blank lines in DATA statements

**URL:** <https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579>\
**Category:** Ruby\
**Created:** [April 23, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579 "2006-04-23T17:15:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/1 "2006-04-23T17:15:37Z")

</div>

suppose i have the following piece of code to read some data (input by  
the user) following **END**

while line = DATA.gets  
one\_record = line.chomp!.split

# do stuff

end

**END**

bought 2 widgets 17.99  
sold 12 widgets 22.49

bought 11 things 12.99

sold 5 things 10.49

as you can see, there is a blank line ahead of the first line of data (i  
don’t want that), and there may be one or more blank lines or lines  
containing spaces after the data or even between the lines of data.

i can’t control what the user will do here, but i need to take it into  
account. any suggestions on how to ensure that any line i read contains  
the 4 desired fields and doesn’t contain anything else (even 4 blank  
spaces like between the last bought and sold records)?

thanks

joe

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/2 "2006-04-23T17:21:45Z")

</div>

Hi –

On Mon, 24 Apr 2006, Joseph Paish wrote:

> **END**  
> don’t want that), and there may be one or more blank lines or lines  
> containing spaces after the data or even between the lines of data.
> 
> i can’t control what the user will do here, but i need to take it into  
> account. any suggestions on how to ensure that any line i read contains  
> the 4 desired fields and doesn’t contain anything else (even 4 blank  
> spaces like between the last bought and sold records)?

Here’s a nice way to avoid worrying about the spaces, though it may  
run aground if you have lines that have non-spaces and are malformed:

require ‘scanf’

DATA.scanf(“%s%d%s%f”) do |action, num, item, price|  
puts “#{action} #{num} #{item} at $#{price}, total $#{price \* num}”  
end

Output (with your sample):

bought 2 widgets at $17.99, total $35.98  
sold 12 widgets at $22.49, total $269.88  
bought 11 things at $12.99, total $142.89  
sold 5 things at $10.49, total $52.45

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” PDF now on sale! [Ruby for Rails](http://www.manning.com/black)  
Paper version coming in early May!

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/3 "2006-04-23T17:40:28Z")

</div>

On Mon, 24 Apr 2006 00:20:46 +0900  
removed\_email\_address@domain.invalid wrote:

> > end  
> > sold 5 things 10.49
> 
> bought 2 widgets at $17.99, total $35.98  
> sold 12 widgets at $22.49, total $269.88  
> bought 11 things at $12.99, total $142.89  
> sold 5 things at $10.49, total $52.45
> 
> David

this is exactly what i needed.

thank you

joe

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/4 "2006-04-23T19:12:57Z")

</div>

Can someone tell me how to unsubscribe?  
This info should be at the bottom of each email.  
Thanks  
JB

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 7:22pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/5 "2006-04-23T19:22:10Z")

</div>

On Sunday 23 April 2006 18:11, John Brookes wrote:

> Can someone tell me how to unsubscribe?  
> This info should be at the bottom of each email.  
> Thanks  
> JB  
> Just send an email to the list controller address  
> removed\_email\_address@domain.invalid  
> with with the body: unsubscribe. More help is available here:  
> [http://www.ruby-lang.org/en/20020104.html](http://www.ruby-lang.org/en/20020104.html). I’ll admit that the interface  
> is  
> perhaps not what many will be used to due to the dominance of  
> mailman-operated lists. Hope this helps,

Alex

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 10:57pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/6 "2006-04-23T22:57:39Z")

</div>

On Mon, 24 Apr 2006 00:42:15 +0900  
removed\_email\_address@domain.invalid wrote:

> > > > **END**  
> > > > don’t want that), and there may be one or more blank lines or lines  
> > > > require ‘scanf’  
> > > > sold 5 things at $10.49, total $52.45  
> > > > joe
> 
> Do be careful, though, if there’s a chance of a malformed line. scanf  
> will just stop. But if the data are as they should be it will work  
> nicely.
> 
> David

ok, thanks for the warning. malformed lines _shouldn’t_ be an issue.

in any event, it looks like it’s time for some more reading (raise,  
catch, throw, etc.) just to learn how to cover that possibility.

joe

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/7 "2006-04-23T23:34:25Z")

</div>

“John Brookes” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Can someone tell me how to unsubscribe?  
> This info should be at the bottom of each email.

Luckily, it’s at the _top_ of each mail 🙂

List-Id: [ruby-talk.ruby-lang.org](http://ruby-talk.ruby-lang.org)  
List-Software: fml [fml 4.0.3 release (20011202/4.0.3)]  
List-Post: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Owner: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Help: [mailto:removed\_email\_address@domain.invalid?body=help](mailto:removed_email_address@domain.invalid?body=help)  
List-Unsubscribe: [mailto:removed\_email\_address@domain.invalid?body=unsubscribe](mailto:removed_email_address@domain.invalid?body=unsubscribe)

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 23, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/8 "2006-04-23T17:43:35Z")

</div>

Hi –

On Mon, 24 Apr 2006, Joseph Paish wrote:

> > > while line = DATA.gets
> > > 
> > > account. any suggestions on how to ensure that any line i read contains  
> > > end
> 
> this is exactly what i needed.
> 
> thank you
> 
> joe

Do be careful, though, if there’s a chance of a malformed line. scanf  
will just stop. But if the data are as they should be it will work  
nicely.

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” PDF now on sale! [Ruby for Rails](http://www.manning.com/black)  
Paper version coming in early May!

---

<div class="post-metadata">

**Author:** ![Joseph\_Paish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@Joseph\_Paish](https://www.ruby-forum.com/u/Joseph_Paish)\
**Post date:** [April 24, 2006, 7:31am UTC](https://www.ruby-forum.com/t/how-to-ensure-no-blank-lines-in-data-statements/58579/9 "2006-04-24T07:31:05Z")

</div>

On 4/23/06, A. S. Bradbury [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[snip]

> Just send an email to the list controller address removed\_email\_address@domain.invalid  
> with with the body: unsubscribe. More help is available here:  
> [http://www.ruby-lang.org/en/20020104.html](http://www.ruby-lang.org/en/20020104.html). I’ll admit that the interface is  
> perhaps not what many will be used to due to the dominance of  
> mailman-operated lists. Hope this helps,
> 
> Alex

When I send a message to removed\_email\_address@domain.invalid containing  
“unsubscribe” as its body and my subscribed email address as both the  
envelope from and the From: header, I receive this cryptic reply and  
continue receiving list messages:

* * *

Date: Mon, 24 Apr 2006 13:45:39 +0900  
From: removed\_email\_address@domain.invalid  
Reply-To: removed\_email\_address@domain.invalid  
Subject: fml Command Status report (ruby-talk ML)  
To: removed\_email\_address@domain.invalid

> > > unsubscribe  
> > > set UNSUBSCRIBE =\> BYE  
> > > BYE command got some errors

Hmm,…, modifying delivery list fails.  
BYE [removed\_email\_address@domain.invalid] accepted  
change member list not recipient list

removed\_email\_address@domain.invalid, Be Seeing You!

* * *

I have no idea what that means, even after looking at the  
five-year-old Perl code that’s printing it. When I try sending the  
message from another address, I receive a different error message  
stating that the address isn’t subscribed, so I’m reasonably convinced  
that I’m using the correct address.

My messages to removed\_email\_address@domain.invalid go unanswered. If the  
list admin is reading this, please unsubscribe me. Thanks!
