Google Groups Home
Help | Sign in
Hash of Arrays nItems problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
hoy...@gmail.com  
View profile  
 More options Mar 17 2006, 5:11 pm
Newsgroups: comp.lang.ruby
From: hoy...@gmail.com
Date: 17 Mar 2006 14:11:01 -0800
Local: Fri, Mar 17 2006 5:11 pm
Subject: Hash of Arrays nItems problem
I'm having a bit of problem using a hash of arrays.  It appears that
nitems are wrong for the individual elements are wrong when I do this:

#!/usr/bin/env ruby
$:.unshift(File.join('..', 'lib'))
require 'http-access2'

h = HTTPAccess2::Client.new()
element = Hash.new([])

while urlstr = ARGV.shift
  response = h.get(urlstr) { |data|

data.gsub(/<(description|title|link)>(.+)<\/(description|title|link)>/)
{
      print $1,"\n"
      element[$1].push($2.gsub(/\s\s+/m," "))
    }
  }
end

print "site description ---> ", site_description, "\n"
print "site title ---------> ", site_title, "\n"
print "description.nitems -> ", element['description'].nitems, "\n"
print "title.nitems -------> ", element['title'].nitems, "\n"

site_description = element['description'].shift
site_title = element['title'].shift

while element['description'].nitems > 0
  print element['title'].shift.gsub(/\n+/, ""),"\n"
  print element['description'].shift.gsub(/\n+/, ""),"\n\n"
end

% ruby rss.rb http://involution.com/rss.php
site description ---> involution.com
site title ---------> http://involution.com
description.nitems -> 30
title.nitems -------> 30

There are 10 of each links, putting a print in the hget enclosure shows
that only 10 descriptions, links, and titles are added, but the
individual array sizes are reported as 30.  What am I doing wrong?

Tony


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Klemme  
View profile  
 More options Mar 19 2006, 7:32 am
Newsgroups: comp.lang.ruby
From: "Robert Klemme" <bob.n...@gmx.net>
Date: Sun, 19 Mar 2006 13:32:01 +0100
Local: Sun, Mar 19 2006 7:32 am
Subject: Re: Hash of Arrays nItems problem

hoy...@gmail.com wrote:
> I'm having a bit of problem using a hash of arrays.  It appears that
> nitems are wrong for the individual elements are wrong when I do this:

> #!/usr/bin/env ruby
> $:.unshift(File.join('..', 'lib'))
> require 'http-access2'

> h = HTTPAccess2::Client.new()
> element = Hash.new([])

You want

element = Hash.new {|h,k| h[k] = []}

Otherwise you'll be adding to the *same* single array instance for *all*
elements.

Kind regards

    robert


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hoy...@gmail.com  
View profile  
 More options Mar 19 2006, 5:56 pm
Newsgroups: comp.lang.ruby
From: hoy...@gmail.com
Date: 19 Mar 2006 14:56:26 -0800
Local: Sun, Mar 19 2006 5:56 pm
Subject: Re: Hash of Arrays nItems problem
Oh, snap.  Thanks robert.  I will name my first son Robert in your
honor.  Thanks a million.

Tony Perrie
http://involution.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Klemme  
View profile  
 More options Mar 20 2006, 4:36 am
Newsgroups: comp.lang.ruby
From: Robert Klemme <bob.n...@gmx.net>
Date: Mon, 20 Mar 2006 10:36:23 +0100
Local: Mon, Mar 20 2006 4:36 am
Subject: Re: Hash of Arrays nItems problem

hoy...@gmail.com wrote:
> Oh, snap.  Thanks robert.  I will name my first son Robert in your
> honor.  Thanks a million.

You're welcome.  And I feel humbled.

Kind regards

        robert


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google