Newbie converting brain from perl

how about:

date = “28 Aug 2002”

date, day, month, year = /(\d+) (\w+) (\d+)/.match(date)

well…, you could also petition matz to transfer first entry to last :wink:


-----Original Message-----
From: William Pietri []
Sent: Thursday, August 29, 2002 4:31 AM
Subject: Newbie converting brain from perl

Howdy! As a long time Perl, Java, and Objective-C developer,
I’m quite taken
with Ruby, and I’m busily converting my brain over. But
there’s a Perl
idiom that I’m having trouble translating. In Perl it goes like this:

$date = "28 Aug 2002";
($day, $month, $year) = $date =~ /(\d+) (\w+) (\d+)/;

In Ruby the best I’ve been able to do is this:

date = "28 Aug 2002"
day, month, year = /(\d+) (\w+) (\d+)/.match(date)[1..3]

But that final [1…3] thing seems inelegant, which makes me think I’m
barking up the wrong tree. What’s the best Ruby-style way to do this?

Many thanks,