Follow-up to Perl not for dummies

So if I were to write that bit of Perl code I posted about 3 days ago in Ruby (using the additional functionality provided by Rails), it would look like this:

hash = Hash.from_xml(res.content)
service_id = hash['service']['id']
hash['service']['activities'].each do |item|
if item['name'] == activity
activity_id = item['id']
break
end
end

I’m fairly certain that code is an accurate translation of the Perl snippet, but without reproducing the same situation, I can’t guarantee it. The point is, it is representative of Ruby code, and its significantly more readable syntax.

About these ads
This entry was posted in Computing and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s