Going OOP not always makes things easier and it also does not always make as much sense as the OOP fans claim.
-- The -- advantage of OOP, in my (sometimes not so) humble opinion, is encapsulation.
In your case, this means that you basically put the whole thing in an own class and instead of declaring all variables as globals, you make them private. You can pass the name of the file you want to examine to the constructor of the class and let the method that does the actual work return the result array. This way, all the temporary and worker variables are hidden from the user and the rest of the code --- encapsulation.
-- The -- advantage of OOP, in my (sometimes not so) humble opinion, is encapsulation.
In your case, this means that you basically put the whole thing in an own class and instead of declaring all variables as globals, you make them private. You can pass the name of the file you want to examine to the constructor of the class and let the method that does the actual work return the result array. This way, all the temporary and worker variables are hidden from the user and the rest of the code --- encapsulation.