[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Group by unique entries of a hash
From:       "David A. Black" <dblack () rubypal ! com>
Date:       2009-09-30 17:14:31
Message-ID: alpine.LFD.2.00.0909301311080.1496 () rubypal ! com
[Download RAW message or body]

[Attachment #2 (MULTIPART/MIXED)]

On Thu, 1 Oct 2009, Simon Krahnke wrote:

> * Paul Smith <paul@pollyandpaul.co.uk> (2009-09-29) schrieb:
>
>>>    fields = data.split(",")
>>>    hash = fields[0]
>>>    ocrID = fields[1]
>
> BTW, you could write this as:
>
> hash, ocrID = *data.split(",")
>
> or
>
> hash, ocrID, *ignored = *data.split(",")
>
> if you want to ignore everything behind a second comma, or
>
> hash, ocrID = *data.split(",", 2)
>
> if you want to include a second comma and everything behind it into the
> ocrID string.

I don't think you need the * for any of them. This:

   hash, ocrID = data.split(',')

should be fine for getting the first two values.


David

-- 
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic