--NzB8fVQJ5HfG6fxh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jun 07, 2011 at 01:40:25AM +0900, Robert Klemme wrote:
>=20
> $ seq 1 5 | ruby19 -ne 'p $_'
> "1\n"
> "2\n"
> "3\n"
> "4\n"
> "5\n"

Holy crap.  I had no idea.

I don't think the existence of $_ is really a completely egregious
problem (though I do dislike its ill fit in Ruby).  For a moment there I
thought it was an incomplete implementation of $_, but I realized that
for some reason "puts" and "p" do not work as I would expect in this
context.  Specifically, I would expect these three commands to be
equivalent in effect:

    seq 1 5 | perl -ne 'print'
    seq 1 5 | ruby -ne 'puts'
    seq 1 5 | ruby -ne 'p'

For some reason, though, they are not.  The puts and p versions in Ruby
do not output anything at all (other than blank lines in the case of
puts).  If I use print in Ruby, though, the behavior is equivalent:

    seq 1 5 | ruby -ne 'print'

I suspect I missed something that should be obvious but I have no idea
why puts and p do not seem to be aware of $_ while print does behave as
though aware of it in Ruby.

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

--NzB8fVQJ5HfG6fxh
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk3tCLEACgkQ9mn/Pj01uKUkfQCbBENi8L3MsWEAVnggIAMRI0P0
LW4An0UexAu5FgcoisERtCjwrUKrlngC
=zPH2
-----END PGP SIGNATURE-----

--NzB8fVQJ5HfG6fxh--

On Tue, Jun 07, 2011 at 01:40:25AM +0900, Robert Klemme wrote:
>=20
> $ seq 1 5 | ruby19 -ne 'p $_'
> "1\n"
> "2\n"
> "3\n"
> "4\n"
> "5\n"

Holy crap.  I had no idea.

I don't think the existence of $_ is really a completely egregious
problem (though I do dislike its ill fit in Ruby).  For a moment there I
thought it was an incomplete implementation of $_, but I realized that
for some reason "puts" and "p" do not work as I would expect in this
context.  Specifically, I would expect these three commands to be
equivalent in effect:

    seq 1 5 | perl -ne 'print'
    seq 1 5 | ruby -ne 'puts'
    seq 1 5 | ruby -ne 'p'

For some reason, though, they are not.  The puts and p versions in Ruby
do not output anything at all (other than blank lines in the case of
puts).  If I use print in Ruby, though, the behavior is equivalent:

    seq 1 5 | ruby -ne 'print'

I suspect I missed something that should be obvious but I have no idea
why puts and p do not seem to be aware of $_ while print does behave as
though aware of it in Ruby.

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk3tCLEACgkQ9mn/Pj01uKUkfQCbBENi8L3MsWEAVnggIAMRI0P0
LW4An0UexAu5FgcoisERtCjwrUKrlngC
=zPH2
-----END PGP SIGNATURE-----