D
dkmd_nielsen
I have a command line shell that I plan to run over and over again.
It's base functionality is to accept a list of files names and a file
name containing the logic to be applied to the contents of said files.
My shell script contains the logic for accepting the shell commmands
and list of files. However, I am unable to figure out how to accept a
simple block of logic from a separate file and use it as a method
within the shell. An example of the type of logic would be:
# Find parm arg that follows equal sign and upper case it.
# If the arg contains D:\, then change to E:\ if it is
# not a "Work File Directory" parm.
def updatevalue(rec) # rec is the record to update
i = nil # create i
i = parm.index('=')+1 if parm =~ /^[\*\s]|^(BEGIN|END)/
if i # If i has a value
j = rec.length-i # determine length of value
rec[i,j] = rec[i,j].upcase # upper case that portion of text
i = rec.index('D:\\') # Does arg contain D:?
rec = rec[0,i]+'E:'+rec[i+3,rec.length-i] if i && (rec !~ /^Work
File Directory/)
end
rec
end
What I envision is:
E:\> ruby TemplateList.rb -v -f TemplateList.txt -m updatevalue.rb
Where updatevalue.rb is the module I would like to be considered the
processing block applied to all records read.
Within the shell TemplateList.rb is currently: recs.each {|rec|
tmp.write(updatevalue(rec)) }
I just don't know the correct terminology that will lead me to the
correct solution.
It's base functionality is to accept a list of files names and a file
name containing the logic to be applied to the contents of said files.
My shell script contains the logic for accepting the shell commmands
and list of files. However, I am unable to figure out how to accept a
simple block of logic from a separate file and use it as a method
within the shell. An example of the type of logic would be:
# Find parm arg that follows equal sign and upper case it.
# If the arg contains D:\, then change to E:\ if it is
# not a "Work File Directory" parm.
def updatevalue(rec) # rec is the record to update
i = nil # create i
i = parm.index('=')+1 if parm =~ /^[\*\s]|^(BEGIN|END)/
if i # If i has a value
j = rec.length-i # determine length of value
rec[i,j] = rec[i,j].upcase # upper case that portion of text
i = rec.index('D:\\') # Does arg contain D:?
rec = rec[0,i]+'E:'+rec[i+3,rec.length-i] if i && (rec !~ /^Work
File Directory/)
end
rec
end
What I envision is:
E:\> ruby TemplateList.rb -v -f TemplateList.txt -m updatevalue.rb
Where updatevalue.rb is the module I would like to be considered the
processing block applied to all records read.
Within the shell TemplateList.rb is currently: recs.each {|rec|
tmp.write(updatevalue(rec)) }
I just don't know the correct terminology that will lead me to the
correct solution.