What's the matter with my programm:Web Analysis

HTMLRegexp =/(<!–.?–\s>)|
(<(?:[^"’>]|"[^"]"|’[^’]’)+>)|
([^<]
)/xm

data =DATA.read

data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]
if comment
p [“Comment”,comment]
elseif tag
p [“Tag”,tag]
elseif tdata
tdata.gsub!(/\s+/,"")
tdata.sub!(/ $/,"")
p [ “TextData”,tdata] unless tdata.empty?

end
}
END

< A name="FOO" href="foo" attr >foo < A name="BAR" href="bar" attr >bar < A name=BAZ href=baz attr >baz

i run it ,the output is:
syntax error, unexpected ‘<’, expecting $end

^
what’s the problem?how can i solve it?

it’s END not END

-Thomas

Thomas P. wrote:

it’s END not END

-Thomas

i change END into END ,it’s no use.
please run it on your computer to see what happen,think you

Pen T. wrote:

please run it on your computer to see what happen,think you

z.rb:11: undefined method `elseif’ for main:Object (NoMethodError)

That’s trying to tell you something.

At 2010-03-23 12:18AM, “Pen T.” wrote:

HTMLRegexp =/(<!–.?–\s>)|
(<(?:[^"’>]|"[^"]"|’[^’]’)+>)|
([^<]
)/xm

Please consider using a real HTML parser, such as Nokogiri

if comment
p [“Comment”,comment]
elseif tag

"elsif" not "elseif"

On 23 March 2010 11:26, Pen T. [email protected] wrote:

Thomas P. wrote:

it’s END not END

-Thomas

i change END into END ,it’s no use.

please run it on your computer to see what happen,think you

http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#if

there two bugs in my first program :
1、it’s END not END
2、it’s “elsif” not “elseif”
i change my program into
#the filename is: /home/pt/htmlscan_test.rb
HTMLRegexp =/(<!–.?–\s>)|
(<(?:[^"’>]|"[^"]"|’[^’]’)+>)|
([^<]
)/xm

data =DATA.read

data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]
if comment
p [“Comment”,comment]
elsif tag
p [“Tag”,tag]
elsif tdata
tdata.gsub!(/\s+/,"")
tdata.sub!(/ $/,"")
p [ “TextData”,tdata] unless tdata.empty?
end
}
END

< A name="FOO" href="foo" attr >foo < A name="BAR" href="bar" attr >bar < A name=BAZ href=baz attr >baz

there is another problem too:
it can be run on netbeans ide6.8,got correct answer
[“Tag”, “”]
[“Tag”, “”]
[“Tag”, “”]
[“Tag”, “< A name=“FOO” href=“foo” attr >”]
[“TextData”, “foo”]
[“Tag”, “”]
[“Tag”, “< A name=“BAR” href=“bar” attr >”]
[“TextData”, “bar”]
[“Tag”, “”]
[“Tag”, “< A name=BAZ href=baz attr >”]
[“TextData”, “baz”]
[“Tag”, “”]
[“Comment”, “”]
[“Tag”, “”]
[“Tag”, “”]

but when i run it on terminal
pt@pt-laptop:~$ ruby /home/pt/htmlscan_test.rb
/home/pt/htmlscan_test.rb:20: syntax error, unexpected ‘<’, expecting
$end

^

what’s the matter?
can you try it on your computer?
please help me.

i reopen my computer ,run the script,get the correct answer
i still have something want to know

data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]

what is the meaning of
data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]
i want to see material about string#scan method
it’s difficult for me to understand :
data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]
in the script.
can you explain it for me?

On Tue, Mar 23, 2010 at 7:48 PM, Pen T. [email protected] wrote:

end

[“Tag”, “”]
but when i run it on terminal
Posted via http://www.ruby-forum.com/.

It works for me on 1.8.6, 1.8.7, and 1.9.1
http://img13.imageshack.us/img13/122/picture1svu.png

On Tue, Mar 23, 2010 at 8:57 PM, Pen T. [email protected] wrote:

it’s difficult for me to understand :
data.scan(HTMLRegexp){|match|
comment,tag,tdata=match[0…2]
in the script.
can you explain it for me?


Posted via http://www.ruby-forum.com/.

Scan docs are here (this is 1.8.6)
http://ruby-doc.org/core/classes/String.html#M000812