Transfer content of flat file to an array

Scenario …

I have a text file

23
24
56
78
90
89

I want to transfer this content into an array,
numArr=[23,24,56,78,90,89]

How to do it

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have a text file
23
24
56
78
90
89
I want to transfer this content into an array,
numArr=[23,24,56,78,90,89]

File.readlines(“surjit.txt”).map {|item| item.chomp}
=> [“23”, “24”, “56”, “78”, “90”, “89”]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFHO1iTb6UiZnhJiLsRApK1AKCNW3uah81gxjhPRfbycRpidF9ORwCeMY6z
Z8ZmbQqMMG2vUAfkRSzvDb0=
=pKJi
-----END PGP SIGNATURE-----

Surjit N. wrote:

I want to transfer this content into an array,
numArr=[23,24,56,78,90,89]

How to do it
File.readlines, map, to_i.

On Nov 14, 1:15 pm, Surjit N. [email protected]
wrote:

numArr=[23,24,56,78,90,89]
IO.read( ‘myfile.txt’ ).scan( /\d+/ ).map{ |s| s.to_i }

…assuming you don’t have any floating point numbers in there.

On Nov 14, 2007, at 3:15 PM, Surjit N. wrote:

I want to transfer this content into an array,
numArr=[23,24,56,78,90,89]

How to do it

ruby -e ‘p File.readlines(“/tmp/numbers.txt”).map{|line| line.to_i}’

Rob B. http://agileconsultingllc.com
[email protected]