I've got data coming from mysql and some values have leading or trailing spaces.
This is the code I have:
IFS=$':' res=(${vals//$'\t'/:})
for (( i=0 ; i<${#res[#]} ; i++ )); do
echo "$i: ${res[i]}*"
done
is there a simple effective way to ensure there are no leading or trailing space in res[i] ?
Thanks
EDIT
This is the result of my MYSQL query before it goes through IFS.
ZnbMF0 9RrO7 1 SiteA password password 12 1234 1234 456 456 0 0 0 0 0 0 0 0 test#domain.com test user 5 2222 0 0 0 0 server address 0 0 test#domain.com 0 0 0 0 0 0 0 0 0 0 0 0 0 NULL
In MySQL the email addresses have leading and trailing spaces.
Processing through IFS and then Looping though it as :
for (( i=0 ; i<${#res[#]} ; i++ )); do
echo "$i: ${res[i]}*"
done
Results in:
0: ZnbMFO*
1: 9RrO7*
2: 1*
3: SiteA*
4: password*
5: password*
6: 12*
7: 1234*
8: 1234*
9: 456*
10: 456*
11: 0*
12: 0*
13: 0*
14: 0*
15: 0 *
16: 0*
17: 0*
18: 0*
19: test#domain.com *
20: test*
21: user*
22: 5*
23: 2222 *
24: 0*
25: 0 *
26: 0*
27: 0*
28: server*
29: address*
30: 0*
31: 0*
32: test#domain.com *
33: 0*
34: 0*
35: 0*
36: 0*
37: 0*
38: 0*
39: 0 *
40: 0*
41: 0*
42: 0*
43: 0 *
44: 0*
45: 0*
46: NULL*
The * is there just to highlight the trailing space.
Thanks
Let's say you have an array as this one:
arr=('foo bar' 'test#domain.com ' \
' test#domain.com ' ' test#domain.com ')
To check array content using printf:
printf '[%s]\n' "${arr[#]}"
This will show:
[foo bar]
[test#domain.com ]
[ test#domain.com ]
[ test#domain.com ]
Now for leading and trailing space removal:
shopt -s extglob # turn on extended glob
arr=( "${arr[#]/#+([[:blank:]])/}" ) # remove leading space/tab from each element
arr=( "${arr[#]/%+([[:blank:]])/}" ) # remove trailing space/tab from each element
Now if you print array again:
printf '[%s]\n' "${arr[#]}"
It will show:
[foo bar]
[test#domain.com]
[test#domain.com]
[test#domain.com]
Not sure if you would call it simple, but you can use sed:
echo "${res[i]}" | sed 's/^ *\| *$//g'
vals=$' a \t c d'
IFS=$':' res=(${vals//$'\t'/:})
for (( i=0 ; i<${#res[#]} ; i++ )); do
echo X${res[i]}X
res[$i]=$(echo "${res[i]}" | sed 's/^ *\| *$//g')
echo X${res[i]}X
done
Output:
X a X
XaX
X c dX
Xc dX
Related
So I have written a code up in C to print the frequency of every character in a file called "harrypotter1.txt" (the whole first Harry Potter book). It works to the extent that there are random blank spaces printed with " : 0" next to it when it Should only print the character in the file. Below I will list my code, and show the output it prints on to the screen, If someone can help me fix the problem. NOTE: I need to use the struct!
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
struct pair //struct to store frequency and value
{
int frequency;
char value;
};
int main()
{
struct pair table[128]; //set to 128 because these are the main characters
int fd; // file descriptor for opening file
char buffer[1]; // buffer for reading through files bytes
fd = open("harrypotter1.txt", O_RDONLY); // open a file in read mode
for(int j = 0; j < 128; j++)//for loop to initialize the array of pair (struct)
{
table[j].value = j; // table with index j sets the struct char value to equal the index
table[j].frequency = 0; // then the table will initialize the frequency to be 0
}
while((read(fd, buffer, 1)) > 0) // read each character and count frequency
{
int k = buffer[0]; //index k is equal to buffer[0] with integer mask becasue each letter has a ASCII number.
table[k].frequency++; //using the struct pair table with index k to count the frequency of each character in text file
}
close(fd); // close the file
for (int i = 0; i < 128; i++) // use for loop to print frequency of characters
{
printf("%c: %d\n",table[i].value, table[i].frequency); // print characters and its frequency
}
return 0; //end of code
}
Output:
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 3
: 10702
: 0
: 0
: 10702
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
0
: 0
: 0
: 0
: 0
: 70803
!: 474
": 4758
#: 0
$: 0
%: 0
&: 0
': 3141
(: 30
): 33
*: 2
+: 0
,: 5658
-: 1990
.: 6136
/: 0
0: 5
1: 11
2: 3
3: 8
4: 6
5: 2
6: 1
7: 4
8: 1
9: 4
:: 69
;: 135
<: 0
=: 0
>: 0
?: 754
#: 0
A: 703
B: 348
C: 293
D: 685
E: 287
F: 426
G: 492
H: 2996
I: 1393
J: 51
K: 79
L: 209
M: 665
N: 488
O: 332
P: 639
Q: 203
R: 660
S: 844
T: 1055
U: 193
V: 192
W: 653
X: 2
Y: 326
Z: 5
[: 0
\: 1
]: 0
^: 0
_: 0
`: 0
a: 25887
b: 4980
c: 6403
d: 15932
e: 39628
f: 6431
g: 8127
h: 19535
i: 19422
j: 319
k: 3930
l: 14385
m: 6729
n: 21337
o: 25809
p: 4909
q: 217
r: 20990
s: 18870
t: 27993
u: 9562
v: 2716
w: 7744
x: 381
y: 8293
z: 259
{: 0
|: 0
}: 0
~: 1
: 0
*/
The C answer by Allan Wind is good insofar as it produces the correct results, but it does allocate a larger array of characters than the minimum needed to solve the problem. This waste of space is a compromise forced by the fact that C array indices must start at 0 and the first printable character ' ' has a value of 32 and the last printable character '~' has a value of 126.
with Ada.Text_IO; use Ada.Text_IO;
procedure count_graphic_characters is
subtype graphix is Character range ' ' .. '~';
counts : array (graphix) of Natural := (Others => 0);
The_file : File_Type;
C : Character;
begin
Open
(File => The_file, Mode => In_File,
Name => "src\count_graphic_characters.adb");
while not End_Of_File (The_file) loop
Get (File => The_file, Item => C);
counts (C) := counts (C) + 1;
end loop;
Close (The_file);
for I in counts'Range loop
Put_Line (I & ": " & counts (I)'Image);
end loop;
end count_graphic_characters;
This program counts the frequency of characters in its own source file using the Ada programming language.
The subtype graphix is defined to contain all the graphic characters starting at ' ' and ending at '~'. The array name counts is indexed by the characters in the subtype graphix. Each element of the array is an instance of the pre-defined subtype Natural, and is initialized to 0. The array contains exactly enough elements to count every graphic character in the source file.
The program will raise an exception if the file named in the Open procedure cannot be found.
As each character is read from the file that character is used as an index into the counts array and the corresponding element is incremented.
No space is wasted by creating a 128 element array. Instead an array of 95 characters is used. There is also no need to check each array element to determine if the character represented by the index is a printable character since the array index values are only the printable characters.
The output of this program is:
: 132
!: 0
": 4
#: 0
$: 0
%: 0
&: 2
': 6
(: 10
): 10
*: 0
+: 1
,: 3
-: 0
.: 5
/: 0
0: 1
1: 1
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
:: 6
;: 14
<: 0
=: 8
>: 6
?: 0
#: 0
A: 2
B: 0
C: 7
D: 0
E: 1
F: 5
G: 1
H: 0
I: 8
J: 0
K: 0
L: 1
M: 1
N: 2
O: 5
P: 1
Q: 0
R: 1
S: 0
T: 8
U: 0
V: 0
W: 0
X: 0
Y: 0
Z: 0
[: 0
\: 1
]: 0
^: 0
_: 18
`: 0
a: 26
b: 3
c: 21
d: 9
e: 43
f: 8
g: 9
h: 18
i: 22
j: 0
k: 0
l: 17
m: 3
n: 20
o: 22
p: 13
q: 0
r: 24
s: 15
t: 23
u: 13
v: 0
w: 2
x: 4
y: 3
z: 0
{: 0
|: 0
}: 0
~: 1
You can use an array instead of the struct as the value is simply the array index: table[j].value = j;. Initialized the array instead of assigning the initial values in a loop. Added error checking for open. Use isprint() to figure out if we should print a given character:
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
// assumes 2^i to make the bitwise & work below
#define LEN 128
int main() {
unsigned frequency[LEN] = { 0 };
int fd = open("harrypotter1.txt", O_RDONLY);
if(fd == -1) {
printf("%s\n", strerror(errno));
return 1;
}
unsigned char buffer;
while((read(fd, &buffer, 1)) > 0) {
frequency[buffer & (LEN-1)]++;
}
close(fd);
for (int i = 0; i < LEN; i++) {
if(isprint(i))
printf("%c: %u\n", i, frequency[i]);
}
return 0;
}
and using the placing the content "hello world" in the input file, I get the following output:
: 1
!: 0
": 0
#: 0
$: 0
%: 0
&: 0
': 0
(: 0
): 0
*: 0
+: 0
,: 0
-: 0
.: 0
/: 0
0: 0
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
:: 0
;: 0
<: 0
=: 0
>: 0
?: 0
#: 0
A: 0
B: 0
C: 0
D: 0
E: 0
F: 0
G: 0
H: 0
I: 0
J: 0
K: 0
L: 0
M: 0
N: 0
O: 0
P: 0
Q: 0
R: 0
S: 0
T: 0
U: 0
V: 0
W: 0
X: 0
Y: 0
Z: 0
[: 0
\: 0
]: 0
^: 0
_: 0
`: 0
a: 0
b: 0
c: 0
d: 1
e: 1
f: 0
g: 0
h: 1
i: 0
j: 0
k: 0
l: 3
m: 0
n: 0
o: 2
p: 0
q: 0
r: 1
s: 0
t: 0
u: 0
v: 0
w: 1
x: 0
y: 0
z: 0
{: 0
|: 0
}: 0
~: 0
The first 32 ASCII characters (values 0 - 31) are "non-printable" in the sense that they represent characters with special meaning or behavior. You can have your code as it is, but limit the actual print-out to only include "printable" characters. You could start at space ' ' (value 32) and end at 'z' (122) which will give most of the printables (though not just letters).
for (int i = ' '; i <= 'z'; i++) // use for loop to print frequency of characters
{
printf("%c: %d\n",table[i].value, table[i].frequency); // print characters and its frequency
}
From your printout one can see 10702 CR (value 13) and 10702 LF (value 10) revealing that the text file has 10702 newlines and is a Windows text file.
I am trying to write a program in OAMulator that is reflective of this Pseudo-code.
Set highest to 0
Set count to 7
While count > 0
Get newScore
Print newScore
If newScore > highest
Set highest to newScore
Set count to count - 1
Print highest
Stop
This is what I've come up with. We have to use 7 scores and get the highest and print only the highest score. We also have to use a count loop. I entered 0 as a control to start the inputs along with 7 other scores. TO BE CLEAR I AM NOT LOOKING FOR THE AWNSER OR SOLUTION. i am looking to learn why this isnt working and how to make a count loop work with a higherthan loop.
INPUT LIST
0
60
70
80
90
83
76
95
Then I wrote the code as best as I could, but the issue I run into is the count and new score run off the Accumulator. I tried writing another loop to change it but then the two loops don't always run and the count gets messed up or the scores don't get tallied right.
SET 7 #set count to 7
count, STA 100 #store count to slot 100
loopstart, LDA 0 #start loop, load 0
STA 101 #store 0 in slot 101
LDA 0 #load 60
STA 102 #store in slot 102
LDA 101 #load 60
SUB 102 #subract 70
BRP loopstart #if pos then loop, if not go on.
LDA 100 #load count
DEC # count -1
BRP count #if count <0 loop to count
print, STA 102 #print highest
HLT
here is the trace and memory
TRACE
0: PC=1 IR=[?????] AR=? ACC=? B=?
1: PC=2 IR=[SET 7] AR=1 ACC=7 B=?
2: PC=3 IR=[STA 100] AR=100 ACC=7 B=?
3: PC=4 IR=[LDA 0] AR=0 ACC=0 B=?
4: PC=5 IR=[STA 101] AR=101 ACC=0 B=?
5: PC=6 IR=[LDA 0] AR=0 ACC=60 B=?
6: PC=7 IR=[STA 102] AR=102 ACC=60 B=?
7: PC=8 IR=[LDA 101] AR=101 ACC=0 B=?
8: PC=9 IR=[SUB 102] AR=102 ACC=-60 B=60
9: PC=10 IR=[BRP 3] AR=9 ACC=-60 B=60
10: PC=11 IR=[LDA 100] AR=100 ACC=7 B=60
11: PC=12 IR=[DEC] AR=11 ACC=6 B=60
12: PC=2 IR=[BRP 2] AR=12 ACC=6 B=60
13: PC=3 IR=[STA 100] AR=100 ACC=6 B=60
14: PC=4 IR=[LDA 0] AR=0 ACC=70 B=60
15: PC=5 IR=[STA 101] AR=101 ACC=70 B=60
16: PC=6 IR=[LDA 0] AR=0 ACC=80 B=60
17: PC=7 IR=[STA 102] AR=102 ACC=80 B=60
18: PC=8 IR=[LDA 101] AR=101 ACC=70 B=60
19: PC=9 IR=[SUB 102] AR=102 ACC=-10 B=80
20: PC=10 IR=[BRP 3] AR=9 ACC=-10 B=80
21: PC=11 IR=[LDA 100] AR=100 ACC=6 B=80
22: PC=12 IR=[DEC] AR=11 ACC=5 B=80
23: PC=2 IR=[BRP 2] AR=12 ACC=5 B=80
24: PC=3 IR=[STA 100] AR=100 ACC=5 B=80
25: PC=4 IR=[LDA 0] AR=0 ACC=90 B=80
26: PC=5 IR=[STA 101] AR=101 ACC=90 B=80
27: PC=6 IR=[LDA 0] AR=0 ACC=83 B=80
28: PC=7 IR=[STA 102] AR=102 ACC=83 B=80
29: PC=8 IR=[LDA 101] AR=101 ACC=90 B=80
30: PC=9 IR=[SUB 102] AR=102 ACC=7 B=83
31: PC=3 IR=[BRP 3] AR=9 ACC=7 B=83
32: PC=4 IR=[LDA 0] AR=0 ACC=76 B=83
33: PC=5 IR=[STA 101] AR=101 ACC=76 B=83
34: PC=6 IR=[LDA 0] AR=0 ACC=95 B=83
35: PC=7 IR=[STA 102] AR=102 ACC=95 B=83
36: PC=8 IR=[LDA 101] AR=101 ACC=76 B=83
37: PC=9 IR=[SUB 102] AR=102 ACC=-19 B=95
38: PC=10 IR=[BRP 3] AR=9 ACC=-19 B=95
39: PC=11 IR=[LDA 100] AR=100 ACC=5 B=95
40: PC=12 IR=[DEC] AR=11 ACC=4 B=95
41: PC=2 IR=[BRP 2] AR=12 ACC=4 B=95
42: PC=3 IR=[STA 100] AR=100 ACC=4 B=95
Error: Attempt to read missing input
43: PC=4 IR=[LDA 0] AR=0 ACC=? B=95
Abort: 43 instructions executed.
MEMORY
1. SET 7
2. STA 100
3. LDA 0
4. STA 101
5. LDA 0
6. STA 102
7. LDA 101
8. SUB 102
9. BRP 3
10. LDA 100
11. DEC
12. BRP 2
13. STA 102
14. HLT
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100. 4
101. 76
102. 95
I figured it out. It took me hours. almost days.
SET 8 #set count to 8
STA 100 #store in slot 100
SET 0
STA 102 #slot 0 as highest
loopstart, LDA 100 #Load count
DEC #count -1
BRZ print # if count is 0 print
STA 100 # if count is more than 1 store
LDA 0 #load ACC
STA 101 #store ACC in 101
LDA 101 #load Number
SUB 102 #subract highest
BRP while
BR loopstart
print, LDA 102
STA 0
HLT
while, LDA 101
STA 102 #if ACC is positive store as highest
BR loopstart
There doesn't seem to be much help on the internet for OAM assembly language so i posted the answer for others in the future.
I am trying to install Bitnami Redmine 4.1.1-8 on a MS SQL 2107 server from a Windows 10 Pro computer.
This is a clean computer with no other versions of Redmine. Unfortunately, every time I try to execute the command bundle exec thin -e production start I get this error:
C:\Bitnami\redmine-4.1.1-8\apps\redmine\htdocs> bundle exec thin -e production start
Using rack adapter
Traceback (most recent call last):
86: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/bin/thin:23:in <main>'
85: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/bin/thin:23:inload'
84: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/bin/thin:6:in <top (required)>'
83: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/thin/runner.rb:159:inrun!'
82: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/thin/runner.rb:203:in run_command'
81: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/thin/controllers/controller.rb:74:instart'
80: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/thin/controllers/controller.rb:170:in load_adapter'
79: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/rack/adapter/loader.rb:42:infor'
78: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/rack/adapter/loader.rb:33:in load'
77: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/thin-1.7.2-x64-mingw32/lib/rack/adapter/loader.rb:33:ineval'
76: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/config.ru:1:in <main>'
75: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/config.ru:1:innew'
74: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/rack-2.2.3/lib/rack/builder.rb:125:in initialize'
73: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/rack-2.2.3/lib/rack/builder.rb:125:ininstance_eval'
72: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/config.ru:3:in block in <main>'
71: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/config.ru:3:inrequire'
70: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/config/environment.rb:16:in <top (required)>'
69: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/application.rb:361:ininitialize!'
68: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/initializable.rb:60:in run_initializers'
67: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:205:intsort_each'
66: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:226:in tsort_each'
65: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:347:ineach_strongly_connected_component'
64: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:347:in call'
63: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:347:ineach'
62: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:349:in block in each_strongly_connected_component'
61: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:431:ineach_strongly_connected_component_from'
60: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component'
59: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/tsort.rb:228:inblock in tsort_each'
58: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/initializable.rb:61:in block in run_initializers'
57: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/initializable.rb:32:inrun'
56: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/initializable.rb:32:in instance_exec'
55: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/application/finisher.rb:69:inblock in '
54: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/application/finisher.rb:69:in each'
53: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:356:ineager_load!'
52: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:475:in eager_load!'
51: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:475:ineach'
50: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:477:in block in eager_load!'
49: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:477:ineach'
48: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/railties-5.2.4.2/lib/rails/engine.rb:478:in block (2 levels) in eager_load!'
47: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:246:inrequire_dependency'
46: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:334:in depend_on'
45: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:356:inrequire_or_load'
44: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:37:in load_interlock'
43: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies/interlock.rb:13:inloading'
42: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/concurrency/share_lock.rb:151:in exclusive'
41: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies/interlock.rb:14:inblock in loading'
40: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:37:in block in load_interlock'
39: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:378:inblock in require_or_load'
38: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in require'
37: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:257:inload_dependency'
36: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in block in require'
35: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:inrequire'
34: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/issue_query.rb:20:in <top (required)>'
33: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/issue_query.rb:36:in'
32: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/issue_query.rb:36:in new'
31: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/query.rb:31:ininitialize'
30: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/query.rb:91:in groupable'
29: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/user.rb:816:incurrent'
28: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/app/models/user.rb:822:in anonymous'
27: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/scoping/default.rb:34:inunscoped'
26: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/core.rb:287:in relation'
25: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/inheritance.rb:84:infinder_needs_type_condition?'
24: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/inheritance.rb:78:in descends_from_active_record?'
23: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/model_schema.rb:336:incolumns_hash'
22: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/model_schema.rb:456:in load_schema'
21: from C:/Bitnami/redmine-4.1.1-8/ruby/lib/ruby/2.5.0/monitor.rb:235:inmon_synchronize'
20: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/model_schema.rb:459:in block in load_schema'
19: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/attribute_decorators.rb:51:inload_schema!'
18: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/attributes.rb:234:in load_schema!'
17: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/model_schema.rb:466:inload_schema!'
16: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:90:in connection'
15: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:118:inretrieve_connection'
14: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in retrieve_connection'
13: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:inconnection'
12: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in checkout'
11: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:inacquire_connection'
10: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in try_to_checkout_new_connection'
9: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:incheckout_new_connection'
8: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in new_connection'
7: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/sqlserver_base.rb:13:insqlserver_connection'
6: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/sqlserver_base.rb:13:in new'
5: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/connection_adapters/sqlserver_adapter.rb:64:ininitialize'
4: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/connection_adapters/sqlserver_adapter.rb:365:in connect'
3: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/connection_adapters/sqlserver_adapter.rb:379:indblib_connect'
2: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/activerecord-sqlserver-adapter-5.2.1/lib/active_record/connection_adapters/sqlserver_adapter.rb:379:in new'
1: from C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/tiny_tds-2.1.3-x64-mingw32/lib/tiny_tds/client.rb:60:ininitialize'
C:/Bitnami/redmine-4.1.1-8/apps/redmine/htdocs/vendor/bundle/ruby/2.5.0/gems/tiny_tds-2.1.3-x64-mingw32/lib/tiny_tds/client.rb:60:in `connect': Unable to connect: Adaptive Server is unavailable or does not exist (127.0.0.1) (TinyTds::Error)
Here's my full database/yml file:
production:
adapter: sqlserver
host: 127.0.0.1
port: 1433
database: DATABESE
username: user
password: "passwordpassword"
encoding: utf8
I am trying to install the program on a production MS SQL server of our company so that we can keep track of the employees activities, and I would be grateful for any help.
Quite by accident, I managed to solve this problem myself.
It is necessary to specify the DNS server name, and not its IP, as I did.
After making all the changes to the adapter and connecting to the SQL server, you must run the procedure bundle update
After this shut dawn all server connections from Bitnami Stack Manager Tool
Run bundle exec rake db:migrate RAILS_ENV=production
Re-start all server connections from Bitnami Stack Manager Tool
And that's all about it.
I was implementing Command-line arguments with C , And I shocked when the Arguments Array start acting strange when it passes the number of the argument given. here is the code :
#include <stdio.h>
int main(int a, char *arra[]){
/*
for(int i = 1;i<a;i++){
printf("Arguments N%d -> %s\n",i+1,arra[i]);
}
printf("Totale Arguments:%d\n",a-1);
*/
for(int i = 0;i<=49 ;i++){
printf("%d: -> %s\n--------------------------------------
------\n",i,arra[i]);
}
return 0;
}
My question is how did the array have access to the Linux Terminal variable like the Path variable PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
And the Output was like :
0: -> ./list
--------------------------------------------
1: -> hi
--------------------------------------------
2: -> 234
--------------------------------------------
3: -> hello
--------------------------------------------
4: -> (null)
--------------------------------------------
5: -> LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
--------------------------------------------
6: -> XDG_MENU_PREFIX=gnome-
--------------------------------------------
7: -> LANG=en_US.UTF-8
--------------------------------------------
8: -> GDM_LANG=en_US.UTF-8
--------------------------------------------
9: -> DISPLAY=:1
--------------------------------------------
10: -> COLORTERM=truecolor
--------------------------------------------
11: -> USERNAME=root
--------------------------------------------
12: -> XDG_VTNR=2
--------------------------------------------
13: -> SSH_AUTH_SOCK=/run/user/0/keyring/ssh
--------------------------------------------
14: -> XDG_SESSION_ID=7
--------------------------------------------
15: -> USER=root
--------------------------------------------
16: -> DESKTOP_SESSION=gnome
--------------------------------------------
17: -> GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/bbdf3fc7_241a_437d_86d0_982594cbb92d
--------------------------------------------
18: -> PWD=/root/Documents/Programming/c
--------------------------------------------
19: -> HOME=/root
--------------------------------------------
20: -> SSH_AGENT_PID=1581
--------------------------------------------
21: -> QT_ACCESSIBILITY=1
--------------------------------------------
22: -> XDG_SESSION_TYPE=x11
--------------------------------------------
23: -> XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/
--------------------------------------------
24: -> XDG_SESSION_DESKTOP=gnome
--------------------------------------------
25: -> GJS_DEBUG_OUTPUT=stderr
--------------------------------------------
26: -> GTK_MODULES=gail:atk-bridge
--------------------------------------------
27: -> WINDOWPATH=2
--------------------------------------------
28: -> TERM=xterm-256color
--------------------------------------------
29: -> SHELL=/bin/bash
--------------------------------------------
30: -> VTE_VERSION=5202
--------------------------------------------
31: -> XDG_CURRENT_DESKTOP=GNOME
--------------------------------------------
32: -> GPG_AGENT_INFO=/run/user/0/gnupg/S.gpg-agent:0:1
--------------------------------------------
33: -> GNOME_TERMINAL_SERVICE=:1.67
--------------------------------------------
34: -> SHLVL=1
--------------------------------------------
35: -> XDG_SEAT=seat0
--------------------------------------------
36: -> GDMSESSION=gnome
--------------------------------------------
37: -> GNOME_DESKTOP_SESSION_ID=this-is-deprecated
--------------------------------------------
38: -> LOGNAME=root
--------------------------------------------
39: -> DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus
--------------------------------------------
40: -> XDG_RUNTIME_DIR=/run/user/0
--------------------------------------------
41: -> XAUTHORITY=/run/user/0/gdm/Xauthority
--------------------------------------------
42: -> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
--------------------------------------------
43: -> GJS_DEBUG_TOPICS=JS ERROR;JS LOG
--------------------------------------------
44: -> SESSION_MANAGER=local/FXMACO:#/tmp/.ICE-unix/1529,unix/FXMACO:/tmp/.ICE-unix/1529
--------------------------------------------
45: -> _=./list
--------------------------------------------
46: -> OLDPWD=/root/Documents/Books
--------------------------------------------
47: -> (null)
--------------------------------------------
Segmentation fault
for(int i = 0;i<=49 ;i++){
as we see here your argument list is shorter than 50 elements
It is good to use standard names and to take into the account number of arguments passed (that is the reason of the argc)
int main(int argc char *argv[])
{
for(int i = 0;i < argc ;i++){
I'm writing this to avoid a O(n!) time complexity but I only have pseudocode right now because there are some things I'm unsure about implementing.
This is the format of the file that I want to pass into this script. The data is sorted by the third column -- the start position.
93 Blue19 1 82
87 Green9 1 7912
76 Blue7 2 20690
65 Red4 2 170
...
...
256 Orange50 17515 66740
166 Teal68 72503 123150
228 Green89 72510 114530
Explanation of the code:
I want to create an array of arrays to find when two pieces of information have overlapping lengths.
Columns 3 and 4 of the input file are start and stop positions on a single track line. If any row(x) has a position in column 3 that is shorter than the position in column 4 in any row(y) then this means that x starts before y ends and there is some overlap.
I want to find every row that overlaps with asnyrow without having to compare every row to every row. Because they are sorted I simply add a string to an inner array of the array which represents one row.
If the new row being looked at does not overlap with one of the rows already in the array then (because the array is sorted by the third column) no further row will be able to overlap with the row in the array and it can be removed.
This is what I have an idea of
#!/usr/bin/perl -w
use strict;
my #array
while (<>) {
my thisLoop = ($id, $name, $begin, $end) = split;
my #innerArray = split; # make an inner array with the current line, to
# have strings that will be printed after it
push #array(#innerArray)
for ( #array ) { # loop through the outer array being made to see if there
# are overlaps with the current item
if ( $begin > $innerArray[3]) # if there are no overlaps then print
# this inner array and remove it
# (because it is sorted and everything
# else cannot overlap because it is
# larger)
# print #array[4-]
# remove this item from the array
else
# add to array this string
"$id overlap with innerArray[0] \t innerArray[0]: $innerArray[2], $innerArray[3] "\t" $id : $begin, $end
# otherwise because there is overlap add a statement to the inner
# array explaining the overlap
The code should produce something like
87 overlap with 93 93: 1 82 87: 1 7982
76 overlap with 93 93: 1 82 76: 1 20690
65 overlap with 93 93: 1 82 65: 2 170
76 overlap with 87 87: 1 7912 76: 2 20690
65 overlap with 87 87: 1 7912 65: 2 170
65 overlap with 76 76: 2 20690 65: 2 170
256 overlap with 76 76: 2 20690 256: 17515 66740
228 overlap with 166 166: 72503 123150 228: 72510 114530
This was tricky to explain so ask me if you have any questions
I am using the posted input and output files as a guide on what is required.
A note on complexity. In principle, each line has to be compared to all following lines. The number of operations actually carried out depends on the data. Since it is stated that the data is sorted on the field to be compared the inner loop iterations can be cut as soon as overlapping stops. A comment on complexity estimate is at the end.
This compares each line to the ones following it. For that all lines are first read into an array. If the data set is very large this should be changed to read line by line and then the procedure turned around, to compare the currently read line to all previous. This is a very basic approach. It may well be better to build auxiliary data structures first, possibly making use of suitable libraries.
use warnings;
use strict;
my $file = 'data_overlap.txt';
my #lines = do {
open my $fh, '<', $file or die "Can't open $file -- $!";
<$fh>;
};
# For each element compare all following ones, but cut out
# as soon as there's no overlap since data is sorted
for my $i (0..$#lines)
{
my #ref_fields = split '\s+', $lines[$i];
for my $j ($i+1..$#lines)
{
my #curr_fields = split '\s+', $lines[$j];
if ( $ref_fields[-1] > $curr_fields[-2] ) {
print "$curr_fields[0] overlap with $ref_fields[0]\t" .
"$ref_fields[0]: $ref_fields[-2] $ref_fields[-1]\t" .
"$curr_fields[0]: $curr_fields[-2] $curr_fields[-1]\n";
}
else { print "\tNo overlap, move on.\n"; last }
}
}
With the input in file 'data_overlap.txt' this prints
87 overlap with 93 93: 1 82 87: 1 7912
76 overlap with 93 93: 1 82 76: 2 20690
65 overlap with 93 93: 1 82 65: 2 170
No overlap, move on.
76 overlap with 87 87: 1 7912 76: 2 20690
65 overlap with 87 87: 1 7912 65: 2 170
No overlap, move on.
65 overlap with 76 76: 2 20690 65: 2 170
256 overlap with 76 76: 2 20690 256: 17515 66740
No overlap, move on.
No overlap, move on.
No overlap, move on.
228 overlap with 166 166: 72503 123150 228: 72510 114530
A comment on complexity
Worst case Each element has to be compared to every other (they all overlap). This means that for each element we need N-1 comparisons, and we have N elements. This is O(N^2) complexity. This complexity is not good for operations that are used often and on potentially large data sets, like what libraries do. But it is not necessarily bad for a particular problem -- the data set still needs to be quite large for that to result in prohibitively long runtimes.
Best case Each element is compared only once (no overlap at all). This implies N comparisons, thus O(N) complexity.
Average Let us assume that each element overlaps with a "few" next ones, let us say 3 (three). This means that there would be 3N comparisons. This is still O(N) complexity. This holds as long as the number of comparisons does not depend on the length of the list (but is constant), which is a very reasonable typical scenario here. This is good.
Thanks to ikegami for bringing this up in the comment, along with the estimate.
Remember that the importance of the computational complexity of a technique depends on its use.
This produces exactly the output that you asked for given your sample data as input. It runs in well under one millisecond
Do you have other constraints that you haven't explained? Making your code run faster should never be an end in itself. There is nothing inherently wrong with an O(n!) time complexity: it is the execution time that you must consider, and if your code is fast enough then your job is done
use strict;
use warnings 'all';
my #data = map [ split ], grep /\S/, <DATA>;
for my $i1 ( 0 .. $#data ) {
my $v1 = $data[$i1];
for my $i2 ( $i1 .. $#data ) {
my $v2 = $data[$i2];
next if $v1 == $v2;
unless ( $v1->[3] < $v2->[2] or $v1->[2] > $v2->[3] ) {
my $statement = sprintf "%d overlap with %d", $v2->[0], $v1->[0];
printf "%-22s %d: %d %-7d %d: %d %-7d\n", $statement, #{$v1}[0, 2, 3], #{$v2}[0, 2, 3];
}
}
}
__DATA__
93 Blue19 1 82
87 Green9 1 7912
76 Blue7 2 20690
65 Red4 2 170
256 Orange50 17515 66740
166 Teal68 72503 123150
228 Green89 72510 114530
output
87 overlap with 93 93: 1 82 87: 1 7912
76 overlap with 93 93: 1 82 76: 2 20690
65 overlap with 93 93: 1 82 65: 2 170
76 overlap with 87 87: 1 7912 76: 2 20690
65 overlap with 87 87: 1 7912 65: 2 170
65 overlap with 76 76: 2 20690 65: 2 170
256 overlap with 76 76: 2 20690 256: 17515 66740
228 overlap with 166 166: 72503 123150 228: 72510 114530