From: Eric Hodel Date: 2003-09-21T07:19:32-07:00 Subject: Re: RCR: New interpreter switch --98e8jtXdkpgskNou Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Martin DeMello (martindemello@yahoo.com) wrote: > One place where perl's heavy use of implicit variables scores is in > quick one-liners from the command prompt. I think ruby would be more > appealing in that area if it had a switch that ran the following loop: >=20 > while gets > print $_.instance_eval { > ... > } > end >=20 > This would generalise the existing technique of mixing a few String > methods like gsub and scan into Kernel and having them act implicitly on > $_. Its already got that, use ruby -h. -n and -p do those things Additionally: $ ri Kernel#gets ----------------------------------------------------------- Kernel::gets gets( aString=3D$/ ) -> aString or nil ------------------------------------------------------------------------ Returns (and assigns to $_) the next line from the list of files in ARGV (or $*), or from standard input if no files are present on the command line. Returns nil at end of file. The optional argument specifies the record separator. The separator is included with the contents of each record. A separator of nil reads the entire contents, and a zero-length separator reads the input one paragraph at a time, where paragraphs are divided by two consecutive newlines. If multiple filenames are present in ARGV, gets(nil) will read the contents one file at a time. ARGV << "testfile" print while gets produces: This is line one This is line two This is line three And so on... $ ri Kernel#scan ----------------------------------------------------------- Kernel::scan scan( pattern ) -> anArray scan( pattern ) {| | block } -> $_ ------------------------------------------------------------------------ Equivalent to calling $_.scan. See String#scan on page 378. $ ri Kernel#gsub ----------------------------------------------------------- Kernel::gsub gsub( pattern, replacement ) -> aString gsub( pattern ) {| | block } -> aString ------------------------------------------------------------------------ Equivalent to $_.gsub..., except that $_ receives the modified result. $_ =3D "quick brown fox" gsub /[aeiou]/, '*' #=3D> "q**ck br*wn f*x" $_ #=3D> "q**ck br*wn f*x" --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --98e8jtXdkpgskNou Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/bbN0MypVHHlsnwQRAkEHAJ9mArHDqy71GF78rX93GzlVL1nM4ACgpxRN qd+pJlqLP6xu0tya4jgeRgI= =sKe0 -----END PGP SIGNATURE----- --98e8jtXdkpgskNou--