in reply to Re^2: Sort by -M
in thread Sort by -M

If you have two concurrent processes, then I'm afraid there isn't much you can do to prevent this from happening (at least within the context of what you explained). The best that you can do is possibly to reduce the probability of this happening by filtering the list with a grep.

However, you might ask yourself the following questions: is it really necessary (or useful) to have two concurrent processes to run on the same set of files? If you really want two concurrent processes, can't you "specialize" them, i.e. tell them to work on different file sets (based for example on the file names, file owner or age, or some other property of the files)? I cannot help but think that there is likely something wrong in your process if these two concurrent processes work on the same files, process them and delete some of them.

Another solution would be, when you make your list, to pick up in an AoA or an AoH not only the file names, but also their age. Then your sort could be made on the filename/age pairs you've collected, and you would no longer have a problem when sorting them. But, you'd be processing names of files no longer existing, it may or may not make sense depending on the bigger picture which we don't know.

BTW, these are warnings, not errors. I hate to say that, but, if there is not consequence on your process, you might as well decide to ignore them or even to silence them (although I am very reluctant at this type of decision, that's not what I would do in such a case).

Replies are listed 'Best First'.
Re^4: Sort by -M
by roperl (Beadle) on Feb 02, 2018 at 20:25 UTC
    The point of having two concurrent processes is for High Availability. Both machines run exactly the same workload and provides and Active/Active HA solution. Your right these are warnings. The overall process is working, but I see these messages in my STDERR log file. So that is why I want to address it. I'm going to try and filter with a grep
      As I said, I would probably not do that, but if you're really happy that your programs are working correctly and just want to get rid of the warnings in your log files, then you could silence the warnings (in the smallest possible lexical scope):
      { no warning 'uninitialized', @tmparray = sort { -M "$b" <=> -M "$a" } (@tmparray); }