How do I use heredocs

H

hsun

Hi,

I have a simple test program.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
class QuickTest
=20
def testMe
str =3D <<EOS
Some Application data
EOS =20
puts str
end =20
=20
end

if $0 =3D=3D __FILE__ then

$test =3D QuickTest.new
$test.testMe
end =20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D

I got this error and could not figure out what's wrong?

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
QuickTest.rb:21: can't find string "EOS" anywhere before EOF
QuickTest.rb:6: syntax error
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Can someone help?

I am running Ruby 1.8 on Windows XP


Thanks
 
D

David A. Black

Hi --

Hi,

I have a simple test program.

====================
class QuickTest
def testMe
str = <<EOS
Some Application data
EOS puts str
end end

if $0 == __FILE__ then

$test = QuickTest.new
$test.testMe
end ===========================

I got this error and could not figure out what's wrong?

==============================================
QuickTest.rb:21: can't find string "EOS" anywhere before EOF

You need to put EOS on a line by itself.


David
 
J

Jason Foreman

Hi,
=20
I have a simple test program.
=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
class QuickTest
=20
def testMe
str =3D <<EOS
Some Application data
EOS
puts str
end
=20
end
=20
if $0 =3D=3D __FILE__ then
=20
$test =3D QuickTest.new
$test.testMe
end
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D
=20
I got this error and could not figure out what's wrong?
=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
QuickTest.rb:21: can't find string "EOS" anywhere before EOF
QuickTest.rb:6: syntax error
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=20
Can someone help?
=20
I am running Ruby 1.8 on Windows XP
=20
=20
Thanks
=20
=20

Works fine for me.

Are you 100% sure that "EOS" begins in column 0? This must be true or
it will not be found. Otherwise, change to <<-EOS, where the - will
let you indent the terminator.


Jason
 
H

hsun

----++Omea_Parts_Splitter.102362861438823
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hello David,

The message messed up but I am sure that the EOS is on its own line by itself and I even checked with a HEX editor=2e Here is the file atached=2e

The editor I use is Mondrain=2e

Thanks


Hi --


You need to put EOS on a line by itself=2e

David

----++Omea_Parts_Splitter.102362861438823
Content-Type: application/octet-stream; name="QuickTest.rb"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="QuickTest.rb"

Y2xhc3MgUXVpY2tUZXN0DQogICAgDQogICAgZGVmIHRlc3RNZQ0KICAgICAg
ICBzdHIgPSA8PEVPUw0KICAgIEFwcGxpY2F0aW9uIERhdGENCkVPUyAgICAg
ICAgICAgIA0KICAgICAgICBwdXRzIHN0cg0KICAgIGVuZCAgICANCiAgDQpl
bmQNCg0KaWYgJDAgPT0gX19GSUxFX18gdGhlbg0KDQogICAgJHRlc3QgPSBR
dWlja1Rlc3QubmV3DQogICAgJHRlc3QudGVzdE1lDQplbmQgIA0K
----++Omea_Parts_Splitter.102362861438823--
 
E

Ezra Zygmuntowicz

--Apple-Mail-3--539458889
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

I opened you attachment and it bombed on me as well. But when I
selected the line afetr the terminating EOS I saw that you definitely
did have about 12 spaces after the EOS. I am attching your file back
and now it works.
HTH
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
509-577-7732
(e-mail address removed)

--Apple-Mail-3--539458889
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-ruby-script;
x-unix-mode=0644;
x-mac-hide-extension=yes;
name="QuickTest.rb"
Content-Disposition: attachment;
filename=QuickTest.rb

class QuickTest=0D
=0D
def testMe=0D
str =3D<<EOS=0D
Application Data=0D
EOS=0D
puts str=0D
end =0D
=0D
end=0D
=0D
if $0 =3D=3D __FILE__ then=0D
=0D
$test =3D QuickTest.new=0D
$test.testMe=0D
end =0D

--Apple-Mail-3--539458889
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed



Hello David,

The message messed up but I am sure that the EOS is on its own line
by itself and I even checked with a HEX editor. Here is the file
atached.

The editor I use is Mondrain.

Thanks




--Apple-Mail-3--539458889--
 
H

hsun

Hello Ezra,

Thanks, it works now. maybe I should trun the EOL mark on from now on.


Thanks for everyone that offered help
 
R

Robert Klemme

hsun said:
Hello Ezra,

Thanks, it works now. maybe I should trun the EOL mark on from now on.

Having the editor remove trailing white space automatically when saving is
a good idea. This feature is present in almost every serious editor.

robert
 
G

Gavin Kistner

--Apple-Mail-3--485321224
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Having the editor remove trailing white space automatically when
saving is
a good idea. This feature is present in almost every serious editor.

And even in some of the flippant ones.

--Apple-Mail-3--485321224--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,184
Latest member
ZNOChrista

Latest Threads

Top