From: Matthew Kerwin Date: 2012-12-20T08:19:14+09:00 Subject: Re: Perl to Ruby: regex captures to assignment. --047d7b2e43508c2c5d04d13cbbda Content-Type: text/plain; charset=ISO-8859-1 On 20 December 2012 09:07, Matthew Kerwin wrote: > As it is, the parser is interpreting the ternary operation as the first > item in the list, like: > > tmp = frac_str.match(/\//) \ > ? frac_str.match(/(?:(\S+) )*?(\S+)\/(\S+)/).captures \ > : 0 > w, n, d = tmp, frac_str, d > > Subsequently puts(tmp) is calling Array#to_s which concatenates the > elements, so you see "134" > > Sorry for replying to myself. I just noticed that the Perl code also had an explicit array, : ( 1, $frac_str, 0 ) Those brackety thingies are important, no matter which language you're using. ;) --047d7b2e43508c2c5d04d13cbbda Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 20 December 2012 09:07, Matthew Kerwin <matthew@ke= rwin.net.au> wrote:
As it is, the parser is interpreting the = ternary operation as the first item in the list, like:

=A0 =A0 tmp =3D=A0frac_str.match(/\//) \
=A0 =A0 =A0 ? frac_str.match(/(?:(\S+) )*?(\S+)\/(\S+)/).captures \
=A0 =A0 =A0 : 0
=A0 =A0 w, n, d =3D tmp, frac_str, d

Subsequently puts(tmp) is calling Array#to_s wh= ich concatenates the elements, so you see "134"


Sorry for replying to myself. = =A0I just noticed that the Perl code also had an explicit array,

=A0 =A0=A0=A0: ( 1, $frac_str, 0 )

=
Those brackety thingies are important, no matter which language yo= u're using. =A0;)
--047d7b2e43508c2c5d04d13cbbda--