The first Perl script was written by a colleague. After this function is implemented in Java, no exception is thrown out in the middle. After Perl is used, it is normal.
My colleagues helped me write the code. I modified and debugged it myself, so I had a certain understanding of Perl. Write it down and forget it. Maybe today is a new one.
.
#! /Usr/bin/perl
Use dBi;
# It's so convenient to connect to a database
$ DBH = DBI-> connect ("DBI: mysql: newwap: 172.16.58.36", "root ","");
# Perl Io
Open (F, "data.txt ");
Open (Out, "> result.txt ");
# Hashtable is defined here, which is different from the commonly used array. It is much more convenient than the array here.
Local (% all_count );
Local (% db_count );
Local (% qqs );
$ SQL = $ DBH-> prepare ("select user_id from t_core_user ");
$ SQL-> execute ();
# @ Indicates an array
While (@ qqid = $ SQL-> fetchrow_array ){
$ Qqs {$ qqid [0]} = "0 ";
}
Print ("db operation completed./N ");
While ($ STR = <F> ){
Chomp ($ Str );
# Print ($ Str );
$ CH = substr ($ STR, 0, 1 );
If ($ ch EQ "F "){
Next;
}
@ Arr = Split (// t/, $ Str );
$ QQ = $ arr [0];
$ Time = $ arr [2];
If (length ($ time) <6 ){
Next;
}
# Print ("QQ: $ QQ, time: $ time/N ");
If (substr ($ arr [2], 0, 6) eq "200505 "){
$ All_count {"5"} ++;
If (exists ($ qqs {$ QQ })){
$ Db_count {"5"} ++;
}
}
If (substr ($ arr [2], 0, 6) eq "200506 "){
$ All_count {"6"} ++;
If (exists ($ qqs {$ QQ })){
$ Db_count {"6"} ++;
}
}
If (substr ($ arr [2], 0, 6) eq "200507 "){
$ All_count {"7"} ++;
If (exists ($ qqs {$ QQ })){
$ Db_count {"7"} ++;
}
}
}
Print out ("6:". $ all_count {"5"}. ",". $ db_count {"5"}. "/N ");
Print out ("6:". $ all_count {"6"}. ",". $ db_count {"6"}. "/N ");
Print out ("6:". $ all_count {"7"}. ",". $ db_count {"7"}. "/N ");
Close (f );
Close (out );