KBD

Keith Devens .com

Saturday, July 19, 2008 Flag waving
Men never do evil so completely and cheerfully as when they do it from religious conviction. – Blaise Pascal (attributed)
← WoW Auction House Database SearchONLamp.com -- An Introduction to Erlang →

Daily link icon Wednesday, September 12, 2007

while(<>){...} in Ruby

Re: translate Perl diamond operator to Ruby.

Perl:

while(<>){
  ...
}

Ruby:

ARGF.each do |$_|
  ...
end

At this point I question whether I'd ever use Perl for anything again. Until now, Perl filled a niche where if the code I wanted to write would fit in 10 lines or so, and did a lot of string manipulation, I'd turn to Perl. Otherwise Python. Now I think I'll just use Ruby for everything Smiley

← WoW Auction House Database SearchONLamp.com -- An Introduction to Erlang →

Comments XML gif

Revence (http://freeshells.ch/~revence) wrote:

I moved to Python from Perl. I never really left Perl, because Python is too ... clean. Text munging is dirty stuff. So you need Perl. Plus, I like Perl's philosophy ... and then I met Ruby. I do all my scripting in Ruby. I still do Perl, because ... well, it will be there. Ain't no Unix without it. But when I manage to find Ruby, I use Ruby only. So ... that leaves Py cold. Smiley

∴ Revence | 12-Sep-2007 11:47pm est | http://freeshells.ch/~revence | #10297

Revence (http://freeshells.ch/~revence) wrote:

Actually, I use:

STDIN.each {|x| ...}

Which is more like the diamond operator, because the diamond can take a handle (as in,

<FILEHANDLE>
).
∴ Revence | 14-Sep-2007 8:51am est | http://freeshells.ch/~revence | #10300

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 3 posts

Recent comments XML

Spider solitaire

To answer an earlier question, I am​almost certain every game can be​beat. ...

Jared: Jul 16, 2:20pm

I hate Norton Antivirus

I HATE NORTON ANTIVIRUS IT SUCKS I​GOT AVG IT ROX! AGES TO DELETE​NORTON AN...

wade: Jul 15, 1:44am

Girls, please don't get breast implants

Girls,

   Lots of guys enjoy​smaller breasts.  Several years ago​a well-...

j: Jul 13, 10:13am

Generated in about 0.127s.

(Used 8 db queries)

mobile phone