Well, no offense, but I thought the original post was quite clear. I
obviously thought the problem was complex, hence the posting. The solution
provided doesn't work. Here's why:
Try it on this:
$array[0] = ("-10 10 30 30 30 30");
$array[1] = ("-10 -10 -10 -10 20 30");
$array[2] = ("-12 2 2 2 20 30");
$array[3] = ("10 20 30");
Then,
@stack = map{chop;$_} grep !/\b(\d+ )\1{3}\b/,map "$_", @array;
will yield @stack with 2 elements still.
I do understand the above, I couldn't figure out how to modify it to work
properly.
The regular expression /\b(\d+ )\1{3}\b/ only works provided there is a
space after the digit, which isn't the case for the last number in the
string. I never depicted a space after the last number in each string in
the original post and it isn't trivial (at least for me) how to modify this
to work when it is possible that the repeated number in the string could
occur over the last four numbers of the string.
In other words, if the solution was trivial, someone would have figured it
out by now, and they haven't. In fact, your idea of using a non-whitespace
character doesn't appear to work either. So please don't flame me for
posting a question which has clearly been very difficult for even the best
Perl programmers in the world to figure out.
Thank you
Brian said:
Big Daddy rudely spits TOFU in our faces:
[ rudeness corrected ]
Please express your gratitude by _not_ spitting in our faces.
I found this works provided that all my numbers
are positive numbers. (I know, I didn't portray that in my original
data). Can this be easily modified to work for negative numbers as well?
Actually the regex solution knows nothing of numbers, it works on
_strings_ and happens to constrain itself to strings that consist
entirely of digits.
You could make it handle any non-whitespace string by simply changing
"digit" to "non-whitespace character".
Please try to understand the solutions you are given rather than simply
transcribe them by rote.