Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
It's late, I'm tired. Do my job for me.
#5
Right. So I added
Code:
Prepare_Input_for_Processing() {
  local Title
  for Title in "${ProblematicTitles[@]}"; do
    sed -i -n -e "/$Title/{p;$!d}" -e "/$Title/!H" -e '${g;s/^\n//;p}' "$ComicList"
  done
}

at the top of the functions, and
Code:
Prepare_Input_for_Processing

just before
Code:
while IFS= read -r Comic; do

as well as creating an array, ProblematicTitles, where each element is one of the problematic titles, a few of which are mentioned above.

What Prepare_Input_for_Processing does it it takes all of the issues from ProblematicTitles and puts them on the top of the ComicList text file so that they are no longer in the middle of the issues they were breaking up.

Then I finish the script with a re-sorting of ComicList and OutputFile:
sort -o "$OutputFile" "$OutputFile"
sort -Vo "$ComicList" "$ComicList"

Sure, Prepare_Input_for_Processing is short enough to have been written inline, plus it's just a one-off, not really justifying placing it in a function, but it's cleaner.

Also, did a little more investigation into running functions in a subshell and there's no way I'm going to attempt that for this project. From what I can tell, there is no passing by reference. Yes, the function will take the reference and throw errors if using the same name for the variable, but because the subshell makes copies of all parameters sent to it, any changes made to any variables by the function, whether global or passed by value or reference, are not reflected when the function exits, which is the entire purpose of subshells regarding global variables, but completely defeats the purpose of passing by reference (which isn't a true pass by reference).

As far as I can tell, the only way you can get values back is with the return value (very limited, only the digits 0-255, I believe, maybe a smaller range) and command substitution (the now deprecated backtick `` thingy). I don't even want to start to figure out how to make that work with an associative array.
Getting me free admission into gaming conventions for a decade
Reply


Messages In This Thread
RE: It's late, I'm tired. Do my job for me. - by Oedipussy Rex - 12-09-2024, 02:29 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)