Thx!
Perl’s $" just like OFS in awk which is the output field separator,i.e. that is printed between fields.
···
-----Original Message-----
From: Daniel Carrera [mailto:dcarrera@math.umd.edu]
Sent: Friday, March 28, 2003 3:18 PM
To: ruby-talk@ruby-lang.org
Subject: Re: Newbie question:Does Ruby have the structure of hash’s array like Perl does?
Something like below doesn’t work:
h=Hash.new
h[“a”][0]=“something”
h[“a”][1]=“another thing”
h=Hash.new
h[“a”] = Array.new
h[“a”][0]=“something”
h[“a”][1]=“another thing”
Ruby doesn’t quite have Perl’s “implicit declaration”.
and what’s the equivalence of Perl’s $"?
What does Perl’s $" have?
–
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
depone: depone (di-POHN) verb tr., intr.
To declare under oath.
I’m not sure I understand. Can you give me an example of Perl code that
uses $"?
Regardless, its almost certain that Ruby’s equivalent is $".
AFAIK Ruby has carbon-copied nearly all of Perl’s special variables.
Please do show me what $" does. I’d like to know.
···
On Fri, Mar 28, 2003 at 05:09:09PM +0900, Weng Lei-QCH1840 wrote:
Thx!
Perl’s $" just like OFS in awk which is the output field separator,i.e.
that is printed between fields.
–
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
depone: depone (di-POHN) verb tr., intr.
To declare under oath.
If you interpolate an array into a double-quoted string, it’s the separator
used to join them. In Ruby it would be the default separator for join, which
is $,
$ perl -e ‘@a=(“jim”,“bob”); $“=”-"; print “@a\n”’
jim-bob
$ ruby -e ‘a=[“jim”,“bob”]; puts a.join(“-”)’
jim-bob
$ ruby -e ‘a=[“jim”,“bob”]; $,=“-”; puts a.join’
jim-bob
Perl has $, too, but that’s used as the output field separator when giving
multiple variables to ‘print’. There’s no distinction in Ruby, since “print
a,b,c” is pretty much the same as “print [a,b,c]”
Regards,
Brian.
···
On Fri, Mar 28, 2003 at 05:15:49PM +0900, Daniel Carrera wrote:
Perl’s $" just like OFS in awk which is the output field separator,i.e.
that is printed between fields.
I’m not sure I understand. Can you give me an example of Perl code that
uses $"?
Regardless, its almost certain that Ruby’s equivalent is $".
AFAIK Ruby has carbon-copied nearly all of Perl’s special variables.
Please do show me what $" does. I’d like to know.
A closer example to the Perl would use string interpolation in Ruby:
$ ruby -e ‘a=[“jim”,“bob”]; $,=“-”; puts “hello #{a}”’
hello jim-bob
···
On Fri, Mar 28, 2003 at 08:49:57AM +0000, Brian Candler wrote:
$ ruby -e ‘a=[“jim”,“bob”]; $,=“-”; puts a.join’
jim-bob
Thanks Brian. One thing I like about Ruby is that I really do learn
something new every day.
···
On Fri, Mar 28, 2003 at 05:58:32PM +0900, Brian Candler wrote:
On Fri, Mar 28, 2003 at 08:49:57AM +0000, Brian Candler wrote:
$ ruby -e ‘a=[“jim”,“bob”]; $,=“-”; puts a.join’
jim-bob
A closer example to the Perl would use string interpolation in Ruby:
$ ruby -e ‘a=[“jim”,“bob”]; $,=“-”; puts “hello #{a}”’
hello jim-bob
–
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
depone: depone (di-POHN) verb tr., intr.
To declare under oath.