[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Working on a first plain Ruby script, need help with `join'

Jesse Crockett

7/11/2008 6:39:00 PM

I need help in the block to create a csv file of these entries.

the file, abridged:

@verb_index = "

aah v 1 1 @ 1 0 00865776
abacinate v 1 1 @ 1 0 02168378
abandon v 5 4 @ ~ $ + 5 5 02228031 02227741 02076676 00613393 00614057
abase v 1 3 @ ~ + 1 0 01799794
abash v 1 3 @ ~ + 1 0 01792097
5 Answers

Ib Lis

7/11/2008 6:45:00 PM

0

Jesse Crockett wrote:
> n.split
> n.join(", ") # fails

Do you want to do n.split.join(", ") ?


--
Posted via http://www.ruby-....

Martin DeMello

7/11/2008 6:56:00 PM

0

On Fri, Jul 11, 2008 at 11:38 AM, Jesse Crockett <tefflox@gmail.com> wrote:
>
> n.split
> n.join(", ") # fails

n.split returns a new object containing the array of split entries
from n. you aren't assigning this new object to anything, so it is
silently discarded. the object pointed to by n is unchanged. what you
want is something like

a = n.split
a.join(", ")

or more compactly

n.split.join(", ')

martin

Jesse Crockett

7/11/2008 7:08:00 PM

0

عÙ?ر Ù?Ù?Ù?ب باÙ?ثاÙ?Û? wrote:
> Jesse Crockett wrote:
> > n.split
>> n.join(", ") # fails
>
> Do you want to do n.split.join(", ") ?

Yes. How do I put them into a CSV file? Thank you.
--
Posted via http://www.ruby-....

Rob Biedenharn

7/11/2008 7:18:00 PM

0

On Jul 11, 2008, at 3:08 PM, Jesse Crockett wrote:
>
> Yes. How do I put them into a CSV file? Thank you.


Use FasterCSV (which replaces CSV in the standard lib for Ruby 1.9)

-Rob

Rob Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com




Ib Lis

7/11/2008 7:27:00 PM

0

Jesse Crockett wrote:
> عÙ?ر Ù?Ù?Ù?ب باÙ?ثاÙ?Û? wrote:
>> Do you want to do n.split.join(", ") ?
>
> Yes. How do I put them into a CSV file? Thank you.

Supposing you're reading from stdin or from files passed as argument and
you're writing to stdout:

ARGF.each { |line| puts line.split.join(', ') }

If you want to output to file

output_file = open ('output.cvs', 'w')
ARGF.each { |line| output_file.puts line.split.join(', ') }

[a beginner in Ruby]

--
Posted via http://www.ruby-....