From: Brian Candler Date: 2007-03-25T21:34:23+09:00 Subject: Re: Suggestion: swap name of "puts" and "print" and rename "puts" to "put_s" > irb(main):006:0> $_ = "abcdef" > => "abcdef" > irb(main):007:0> puts "xxx" if /abc/ > (irb):7: warning: regex literal in condition > xxx > => nil > irb(main):008:0> puts "xxx" if /ghi/ > (irb):8: warning: regex literal in condition > => nil > > Ugh. So the rule which says "anything which is not 'nil' or 'false' is true" > is broken in this construct, and this is just to make ruby more perlish. Hmm. Thinking about this a bit more: since this applies only to regexp *literals*, do_something if /foo/ would not be of any use if it were semantically equivalent to do_something if true So I started thinking along the lines of: instead of using global variable $_ as a kind of temporary register to pass data between methods, how could this construct be made more Rubyish? For example, like a case statement, "if /foo/" could translate to "if /foo/ === self" ? But then I realised: perhaps this is all just a marketing scam. Maybe $_ and friends exist in the language, not because they have any real use, but just to sucker in Perl programmers. They see them there, and think "great, this is like Perl, I'll give Ruby a try". Once they're hooked, they won't use them any more than the rest of us do. If that's true, the construct clearly *has* to use $_ to fulfil its purpose :-) Regards, Brian.