12-09-2024, 02:29 PM
(This post was last modified: 07-26-2025, 01:16 PM by Oedipussy Rex.)
Right. So I added
at the top of the functions, and
just before
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.
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_Processingjust before
Code:
while IFS= read -r Comic; doas 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

