#!/usr/bin/perl # create a simple array @coins = ("Quarter","Dime","Nickel"); print "1. \@coins = @coins\n"; # add one element at the end of the array push(@coins, "Penny"); print "2. \@coins = @coins\n"; # add one element at the beginning of the array unshift(@c...
(@array){# 创建子进程my$pid=$pm->startandnext;# 在子进程中执行任务# 将$item写入数据库my$sth=$dbh->prepare("INSERT INTO table_name (column_name) VALUES (?)");$sth->execute($item);$sth->finish();# 结束子进程$pm->finish;}# 等待所有子进程结束$pm->wait_all_children;# ...
#!/usr/bin/perl # create a simple array @coins = ("Quarter","Dime","Nickel"); print "1. \@coins = @coins\n"; # add one element at the end of the array push(@coins, "Penny"); print "2. \@coins = @coins\n"; # add one element at the beginning of the array unshift(@c...
任意一个标量变量可以赋值整形、浮点型、字符型 变量名字由美元符号($)后接perl标识符。 由字母或下划线开头,厚街字母、数字、或者下划线。 变量区分大小写 变量赋值:q表示单引号,qq表示双引号 $test="hello";$test=qq(hello);$test=7;$test=q(hello) 其中()可以换为<>。{},[] 字符串之间的拼接用“.”...
while(my@row=$sth->fetchrow_array() ) { printjoin('\t',@row)."\n"; } $sth->finish(); $dbh->disconnect(); 1.1 连接数据库 1 my$dbh= DBI->connect("DBI:mysql:test:192.168.1.2",'root','password'); 调用DBI的方法DBI->connect来建立一个数据库的连接,如果连接成功则返回一个数据库...
while (my @row=$sth->fetchrow_array()) { my ($first_name, $last_name )=@row; print "First Name=$first_name, Last Name=$last_name\n"; } $sth->finish(); 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 更新数据 my $sth=$dbh->prepare("UPDATE TEST_TABLE ...
如果省略了array 那么移动的就是默认的_ unshift 则是将值写入数组Ø 函数函数定义:sub function/*注:所有的子代码段都必须带,如whilefor常用函数与运算符:方法说明substr(string,offset,length)返回从length个字符开始第一个offset后的字符index(str 4、ing,substring)、rindex(string,substring)从string中查找...
print "Opened database successfully\n"; my $stmt = qq(SELECT id, name, address, salary from COMPANY;); my $sth = $dbh->prepare( $stmt ); my $rv = $sth->execute() or die $DBI::errstr; if($rv < 0) { print $DBI::errstr; } while(my @row = $sth->fetchrow_array()) {...
INSERT INTO users (id, name, age) VALUES (1, '张三', 25); UPDATE users SET age = 26 WHERE id = 1; DELETE FROM users WHERE id = 1; 我们可以使用以下Perl脚本来处理这个迁移日志文件: #!/usr/bin/perl wT use strict; use warnings; ...
();# 执行 SQL 操作# 注释这部分使用的是绑定值操作# $alexa = 20;# my $sth = $dbh->prepare("SELECT name, url# FROM Websites# WHERE alexa > ?");# $sth->execute( $alexa ) or die $DBI::errstr;# 循环输出所有数据while(my@row=$sth->fetchrow_array()){printjoin('\t',@row)."...