# Unexpected kEND, expecting $

**URL:** <https://www.ruby-forum.com/t/unexpected-kend-expecting/77065>\
**Category:** Ruby\
**Created:** [November 23, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/unexpected-kend-expecting/77065 "2006-11-23T22:06:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![comforteagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@comforteagle](https://www.ruby-forum.com/u/comforteagle)\
**Post date:** [November 23, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/unexpected-kend-expecting/77065/1 "2006-11-23T22:06:01Z")

</div>

a = IO.readlines(‘testparsed’)

a.each do |groupname|  
filename = groupname.chomp  
File.open filename  
puts data  
end  
end

Why does this give me: “parse error, unexpected kEND, expecting $” for  
the line with the last ‘end’?

---

<div class="post-metadata">

**Author:** ![comforteagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@comforteagle](https://www.ruby-forum.com/u/comforteagle)\
**Post date:** [November 23, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/unexpected-kend-expecting/77065/2 "2006-11-23T22:12:01Z")

</div>

On 23/11/06, Comfort E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the line with the last ‘end’?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

File.open filename do

Farrel

---

<div class="post-metadata">

**Author:** ![comforteagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@comforteagle](https://www.ruby-forum.com/u/comforteagle)\
**Post date:** [November 23, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/unexpected-kend-expecting/77065/3 "2006-11-23T23:34:12Z")

</div>

On 11/23/06, Comfort E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> a = IO.readlines(‘testparsed’)
> 
> a.each do |groupname|  
> filename = groupname.chomp

- File.open filename

- File.open filename do |file|

- 

```
puts data

```

- 

```
file.puts data # if writing to file is what want to do

```

---

<div class="post-metadata">

**Author:** ![comforteagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@comforteagle](https://www.ruby-forum.com/u/comforteagle)\
**Post date:** [November 24, 2006, 10:09pm UTC](https://www.ruby-forum.com/t/unexpected-kend-expecting/77065/4 "2006-11-24T22:09:14Z")

</div>

Comfort E. wrote:

> the line with the last ‘end’?

a.each do |groupname|  
File.open(groupname.chomp,“w”) { |f| f.write data }  
end
