Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > `&' interpreted as argument prefix

Reply
Thread Tools

`&' interpreted as argument prefix

 
 
Arun Kumar
Guest
Posts: n/a
 
      03-16-2009
Hi,
I'm new to rubi and at present i'm trying to write a sample code for
html extraction and store it in the database. The following is the code
for that :

doc = Hpricot(open("http://www.google.com/"))
(doc/"a").each do |link|
if (link.attributes['class'] == 'gb1')
href = link.inner_text.strip
con = DBI.connect("DBI:Mysql:Sample:localhost", "arunkumar",
"123456")
stat = con.prepare("Insert into hello values ('', ?, 'GK', 71,
'female')")
stat.execute("#{href}")
stat.finish
con.commit
puts "Records have been inserted"
else
puts "Sorry! No matches found."
end
end

When i execute it all works well except a warning saying :
/usr/lib/ruby/gems/1.8/gems/hpricot-0.6.164/lib/hpricot/builder.rb:26:
warning: `&' interpreted as argument prefix

I dont know where went wrong for such a warning to get displayed. Please
help.

Regards
Arun Kumar
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      03-16-2009

On Mar 15, 2009, at 21:14 , Arun Kumar wrote:

> Hi,
> I'm new to rubi and at present i'm trying to write a sample code for
> html extraction and store it in the database. The following is the
> code
> for that :
>
> doc = Hpricot(open("http://www.google.com/"))
> (doc/"a").each do |link|
> if (link.attributes['class'] == 'gb1')
> href = link.inner_text.strip
> con = DBI.connect("DBI:Mysql:Sample:localhost", "arunkumar",
> "123456")
> stat = con.prepare("Insert into hello values ('', ?, 'GK', 71,
> 'female')")
> stat.execute("#{href}")
> stat.finish
> con.commit
> puts "Records have been inserted"
> else
> puts "Sorry! No matches found."
> end
> end
>
> When i execute it all works well except a warning saying :
> /usr/lib/ruby/gems/1.8/gems/hpricot-0.6.164/lib/hpricot/builder.rb:26:
> warning: `&' interpreted as argument prefix


that's from hpricot and won't change anytime soon :/

you may want to switch to mechanize instead. Kill two birds with one
stone.


 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      03-16-2009
Arun Kumar wrote:
> Hi,
> I'm new to rubi and at present i'm trying to write a sample code for
> html extraction and store it in the database. The following is the code
> for that :
>
> doc = Hpricot(open("http://www.google.com/"))


The offending line is:

ele.instance_variable_set("@#{k}", v)

Apparently Google pages contain very complex HTML, to relieve strain on their
servers. Then, Hpricot does not "sanitize" its input. That k variable might
contain a &, which Ruby then warns about. instance_variable_set() creates an
instance variable, like this:

@foo = v

where 'foo' was in k. But if k contains '&foo', you get this:

@&foo = v

You can't write that in raw Ruby, so instance_variable_set() is warning you that
you should not write it in "meta-programming" Ruby either.

But none of this is your fault: It's a bug in Hpricot, which Google's advanced
HTML uncovered.

The conclusion: Switch to Nokogiri. It has an Hpricot compatibility mode, but
its internal engine is libxml, which is one of the industry's leading XML (and
therefor HTML) implementations.

--
Phlip
 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      03-16-2009
2009/3/16 Phlip <(E-Mail Removed)>:
> Arun Kumar wrote:
>>
>> Hi,
>> I'm new to rubi and at present i'm trying to write a sample code for
>> html extraction and store it in the database. The following is the code
>> for that :
>>
>> doc =3D Hpricot(open("http://www.google.com/"))

>
> The offending line is:
>
> =C2=A0 =C2=A0 =C2=A0ele.instance_variable_set("@#{k}", v)
>

Well, I don't think so.

The offending line is:
ele.instance_eval &blk

If you modify it to
ele.instance_eval(&blk)
The warning is gone.

Regards,

Park Heesob

 
Reply With Quote
 
Ryan Davis
Guest
Posts: n/a
 
      03-16-2009

On Mar 16, 2009, at 01:16 , Heesob Park wrote:

> Well, I don't think so.
>
> The offending line is:
> ele.instance_eval &blk
>
> If you modify it to
> ele.instance_eval(&blk)
> The warning is gone.


yup yup...


 
Reply With Quote
 
Ryan Davis
Guest
Posts: n/a
 
      03-16-2009

On Mar 16, 2009, at 08:37 , Ken Bloom wrote:

> Looks fixed if you get Hpricot version 0.6.211 or later.
>
> http://github.com/why/hpricot/commit/
> aa2b51651bee9b3770bc2ecb8f1886b47aee8584


I've said it before and I'll say it again: It isn't fixed until it is
released.


 
Reply With Quote
 
Albert Schlef
Guest
Posts: n/a
 
      03-16-2009
Ryan Davis wrote:
> > warning: `&' interpreted as argument prefix

>
> you may want to switch to mechanize instead. Kill two birds with one
> stone.


Why two? Getting rid of this bug is one bird. Where's the second?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ken Bloom
Guest
Posts: n/a
 
      03-17-2009
On Mon, 16 Mar 2009 14:12:17 -0500, Ryan Davis wrote:

> On Mar 16, 2009, at 08:37 , Ken Bloom wrote:
>
>> Looks fixed if you get Hpricot version 0.6.211 or later.
>>
>> http://github.com/why/hpricot/commit/
>> aa2b51651bee9b3770bc2ecb8f1886b47aee8584

>
> I've said it before and I'll say it again: It isn't fixed until it is
> released.


OK. Somehow I thought that assigning a version number meant it was a
release.



--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
 
Reply With Quote
 
Ken Bloom
Guest
Posts: n/a
 
      03-18-2009
On Mon, 16 Mar 2009 19:42:00 -0500, Ken Bloom wrote:

> On Mon, 16 Mar 2009 14:12:17 -0500, Ryan Davis wrote:
>
>> On Mar 16, 2009, at 08:37 , Ken Bloom wrote:
>>
>>> Looks fixed if you get Hpricot version 0.6.211 or later.
>>>
>>> http://github.com/why/hpricot/commit/
>>> aa2b51651bee9b3770bc2ecb8f1886b47aee8584

>>
>> I've said it before and I'll say it again: It isn't fixed until it is
>> released.

>
> OK. Somehow I thought that assigning a version number meant it was a
> release.


Today it was actually released, and an 0.7 gem is now on RubyForge.

--Ken

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pathname.rb:270: warning: `*' interpreted as argument prefix R.. Kumar 1.9.1 OSX Ruby 11 07-01-2010 09:59 AM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
"static" prefix - to parallel "this" prefix Tim Tyler Java 36 12-10-2004 01:02 AM
Compiled, Not Interpreted! Arpan ASP .Net 1 11-25-2004 03:29 PM
Waveform Interpreted DGW VHDL 0 10-20-2003 04:11 AM



Advertisments