• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Ruby [Ruby] Funcion openwords()

Status
Not open for further replies.

Doddy

Leech
User
Joined
Apr 1, 2012
Messages
169
Reputation
0
Reaction score
406
Points
63
Credits
0
‎13 Years of Service‎
57%
Una simple funcion en ruby para cargar un archivo de texto , la funcion retorna un array con las palabras encontradas en el archivo de texto.

Code:
>
#!usr/bin/ruby
#Funcion openwords()
#Coded By Doddy H

def openwords(file)
 if File.file?(file)
   print "[+] Opening file\n\n"
   ar = File.open(file)
   lineas = ar.readlines
   ar.close
   print "[+] Number of words : ",lineas.length,"\n\n"
   return lineas
 else
   print "[-] Error opening file\n"
 end
end

words = openwords("test.txt")
words.each do |word|
 word = word.chomp
 print "[+] Word : ",word 
end

#The End ?
 
Status
Not open for further replies.
Back
Top