Examples of Perl scripts and Perl DBI Interfaces

Source: Internet
Author: User
Tags perl script

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.