Last active
August 29, 2015 14:27
-
-
Save jasonleonhard/f16af27f28054b9ba572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# reads in user provided parameter for function like ./readsFile2ReadIn.rb file2ReadIn | |
filename = ARGV.first | |
# when user forgets to provide parameter in function call like: ./readsFile2ReadIn4.rb | |
while !filename # if !filename # wont repeat and we want to repeat | |
print "file? \n" | |
file_again = $stdin.gets.chomp | |
print "Oh you want file: #{file_again} \n" # shows filename file2ReadIn which is not important... | |
# print file_again.read | |
txt_again = open(file_again) | |
print txt_again.read # finally reads/opens file | |
end | |
# when user remembers to provide parameter: ./readsFile2ReadIn4.rb file2ReadIn | |
while filename | |
print "file is: #{filename}\n" # shows filename file2ReadIn which is not important... | |
file_again = open(filename) | |
print file_again.read | |
print "Do you want another file? \n" # shows filename file2ReadIn which is not important... | |
file_again = $stdin.gets.chomp # or # filename = gets.chomp | |
txt_again = open(file_again) | |
print txt_again.read | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./data_extractor.rb test.txt
Hello!
./data_extractor.rb
Please enter a filename
test.txt
Hello!