I am looping through a file and using a script that detects leading
spaces (based on a previous post to this forum)
What I want to do is to detect changes in number of leading spaces, for
instance when one line has more, fewer, or the same number of leading
spaces as the previous line.
The problem I am having is with setting a value from within the loop
which is then available on the next loop.
here is an example of the program:
infile = File.new(“input.txt”, “r”)
outfile = File.new(“output.txt”, “w”)
spaces = i[/\A */].length
#the following variable “stored” puts undef every time through, which
means #it’s not retaining the value on the next loop?
if defined?(stored)== true
elsif defined?(stored)== nil
stored = spaces
outfile = File.new(“output.txt”, “r”)
print “>>”, i