perl

安装Percona Tookit

萝らか妹 提交于 2020-02-05 04:27:06
安装PerconaTookit Percona Tookit MySQL服务器管理工​​具包,可以帮助DBA自动化的管理数据库和系统任务。 依赖安装 centos上安装依赖包: yum install -y perl-DBI; yum install -y perl-DBD-mysql; yum install -y perl-IO-Socket-SSL; yum install -y perl-Digest-MD5; yum install -y perl-TermReadKey; 安装 Percona Tookit 工具命令 工具作用 备注 开发类 pt-duplicate-key-checker 列出并删除重复的索引和外键 pt-online-schema-change 在线修改表结构 pt-query-advisor 分析查询语句,并给出建议,有bug 已废弃 pt-show-grants 规范化和打印权限 pt-upgrade 在多个服务器上执行查询,并比较不同 性能类 pt-index-usage 分析日志中索引使用情况,并出报告pt-pmp 为查询结果跟踪,并汇总跟踪结果 pt-index-usage 分析日志中索引使用情况,并出报告 pt-visual-explain 格式化执行计划 pt-table-usage 分析日志中查询并分析表使用情况 pt 2.2新增命令

Perl best practices: file parser using regexes and database storage

不羁的心 提交于 2020-02-05 02:34:34
问题 I'm writing a log file parser in Perl, using regexes that I've stored in a database. My workflow is basically like this: Looping over the file and searching for patterns matching my regexes and then extract them Do something with these matches Store them accordingly in a database Last time I did this I explicitly wrote each regex (not looping through each regex in the database), like this. Now that I'm doing this again I was wondering if there were better solutions out there, better yet

Perl regular expression (regex) fails when I make it optional [duplicate]

六眼飞鱼酱① 提交于 2020-02-05 00:22:11
问题 This question already has an answer here : Reference - What does this regex mean? (1 answer) Closed 13 days ago . I am running the following snippet of code on Perl 5.22: DB<41> x "up 34 days, 22:04 and more" =~ m/.*?(?:(\d+) days).*$/ 0 34 The above code works as expected and pulls out the 34 from "34 days". My question comes in when I make the capture group optional by adding a ? at the end of it like this: DB<4> x "up 34 days, 22:04 and more" =~ m/.*?(?:(\d+) days)?.*$/ 0 undef Why does it

how can I count number of lines after a string match until next especific match occurs

蓝咒 提交于 2020-02-04 22:57:41
问题 I have a file with the following structure (see below), I need help to find the way to match every ">Cluster" string, and for every case count the number of lines until the next ">cluster" and so on until the end of the file. >Cluster 0 0 10565nt, >CL9602.Contig1_All... * 1 1331nt, >CL9602.Contig2_All... at -/98.05% >Cluster 1 0 3798nt, >CL3196.Contig1_All... at +/97.63% 1 9084nt, >CL3196.Contig3_All... * >Cluster 2 0 8710nt, >Unigene21841_All... * >Cluster 3 0 8457nt, >Unigene10299_All... *

Command executed in SSH terminal displays extra line contents

孤人 提交于 2020-02-04 18:59:40
问题 Using Net::SSH::Expect perl module I tried to connect to the server and connection is success. But when its executing the command in connected server and displaying output in current window it displays extra line of output. Below is my code #!/usr/bin/perl use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => 'hostip', #deb-2-scripting ip user => 'user', password => 'password', raw_pty => 1 ); $ssh->run_ssh() or die "SSH process couldn't start: $!"; $ssh->waitfor('password: '); $ssh

Command executed in SSH terminal displays extra line contents

南楼画角 提交于 2020-02-04 18:59:09
问题 Using Net::SSH::Expect perl module I tried to connect to the server and connection is success. But when its executing the command in connected server and displaying output in current window it displays extra line of output. Below is my code #!/usr/bin/perl use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => 'hostip', #deb-2-scripting ip user => 'user', password => 'password', raw_pty => 1 ); $ssh->run_ssh() or die "SSH process couldn't start: $!"; $ssh->waitfor('password: '); $ssh

Print stack trace when “Can't locate object method x via package y” (Perl)

杀马特。学长 韩版系。学妹 提交于 2020-02-04 07:25:52
问题 Chances are I invoke method x on an object of the wrong type, but it's way down in my call stack, so it's not obvious. So: is there a way of always printing a full stack trace when this error occurs? 回答1: To always print a full stack trace add use Carp::Always; or run the program with perl -MCarp::Always script or, with bash PERL5OPT=-MCarp::Always script what sets up the PERL5OPT environment variable and runs the (executable) script . For one, this allows the shebang ( #! ) line in the

Print stack trace when “Can't locate object method x via package y” (Perl)

青春壹個敷衍的年華 提交于 2020-02-04 07:25:20
问题 Chances are I invoke method x on an object of the wrong type, but it's way down in my call stack, so it's not obvious. So: is there a way of always printing a full stack trace when this error occurs? 回答1: To always print a full stack trace add use Carp::Always; or run the program with perl -MCarp::Always script or, with bash PERL5OPT=-MCarp::Always script what sets up the PERL5OPT environment variable and runs the (executable) script . For one, this allows the shebang ( #! ) line in the

Perl DBD::CSV - SQL Syntax - “AND” clause is not working properly

限于喜欢 提交于 2020-02-04 05:08:08
问题 I am running Perl 5.10 on Ubuntu 10.04 and using perl DBI module. I am trying to use the "AND" condition in "WHERE" clause in SQL Query under Perl DBI. I am using the DBD::CSV driver. Please consoider below test.csv: OS,RELEASE,VERSION Ubuntu,Warty,4 Ubuntu,Hoary,5 Ubuntu,Breezy,5 Fedora,Yarrow,1 Fedora,Tettnang,2 Fedora,Stentz,4 Here I want to retrieve the VERSION for Fedora Stentz. Here is my code: #!/usr/bin/perl -w use strict; use DBI; my $table = "test.csv"; my $dbh = DBI->connect ("dbi

Perl: Numerical sort of arrays in a hash

♀尐吖头ヾ 提交于 2020-02-04 04:14:25
问题 I have a hash of arrays, and I need to sort it first on the keys, and then on the values in the array. Here's my simple code: my %myhash; $line1 = "col1 0.999"; $line2 = "col2 0.899"; $line3 = "col2 -0.52"; $line4 = "col2 1.52"; #insert into hash @cols = split(" ", $line1); push @{ $myhash{$cols[0]} }, $line1; @cols = split(" ", $line2); push @{ $myhash{$cols[0]} }, $line2; @cols = split(" ", $line3); push @{ $myhash{$cols[0]} }, $line3; @cols = split(" ", $line4); push @{ $myhash{$cols[0]} }