Linux 下perl编程

xgxgxiong 2010-11-02 11:58:21
xiongguo@ubuntu:~/biancheng/ceshi1$ ls -alRt
.:
total 20
drwxr-xr-x 4 xiongguo xiongguo 4096 2010-11-01 20:39 .
-rw-r--r-- 1 xiongguo xiongguo 3207 2010-11-01 20:39 TestMysql
drwx------ 8 xiongguo xiongguo 4096 2010-11-01 19:34 ..
drwx------ 2 xiongguo xiongguo 4096 2010-11-01 02:03 Mysql
drwx------ 2 xiongguo xiongguo 4096 2010-10-11 16:41 Javas
./Mysql:total 48
drwxr-xr-x 4 xiongguo xiongguo 4096 2010-11-01 20:39 ..
drwx------ 2 xiongguo xiongguo 4096 2010-11-01 02:03 .
-rw-r--r-- 1 xiongguo xiongguo 3100 2010-11-01 02:03 TestMysql
-rw-r--r-- 1 xiongguo xiongguo 2070 2010-11-01 00:25 test3
-rw-r--r-- 1 xiongguo xiongguo 473 2010-10-29 13:21 Iteration
我想问下 在
drwx------ 2 xiongguo xiongguo 4096 2010-10-11 16:41 Javas

./Mysql:
之间的空行是怎么产生的 如果我想把ls -alRt的结果赋值给一个变量 但是我想去除这个空行 该怎么弄
...全文
77 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xgxgxiong 2010-11-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 steptodream 的回复:]
通过perl::DBI操作数据库 大概如下

Perl code

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect('DBI:mysql:dbname:host-ip:port','user','password');
my $sth = $dbh->prepare("sql语句;");
$sth->e……
[/Quote]

谢谢 我这样弄了 但是有个问题
$dbh->disconnect;
这句话报了这样一个错误
Can't locate object method "disconnect" via package "DBI::st" at TestMysqlCheck line 77, <STDIN> line 2.
我刚学 感觉什么都不会 这是为什么啊
steptodream 2010-11-04
  • 打赏
  • 举报
回复
通过perl::DBI操作数据库 大概如下

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect('DBI:mysql:dbname:host-ip:port','user','password');
my $sth = $dbh->prepare("sql语句;");
$sth->execute;
$sth->finish;
$dbh->disconnect;
xgxgxiong 2010-11-04
  • 打赏
  • 举报
回复
这个语句已经搞定 但是能说说你用perl 操作数据库么
我刚刚错在 没有把数组的值后面的换行符给去了 因为 @fileinfos 的值是通过STDIN输入的
xgxgxiong 2010-11-04
  • 打赏
  • 举报
回复
我就在用perl 啊 用perl 怎么直接操数据库啊 我不会
steptodream 2010-11-04
  • 打赏
  • 举报
回复
你不是用perl吗 干嘛不直接用perl操作数据库?
反而要去调用外部命令? 那还不如用shell。
xgxgxiong 2010-11-04
  • 打赏
  • 举报
回复
my ($statement) = 'select * from tab_fileinfo where filepath = "/home/xiongguo/biancheng/ceshi1/Mysql:" and filename = "xgs2"' ;

我把上面的sql语句改为下面的 能给我看下这句话是不是有问题 改过之后 查询没有结果
my @fileinfos = ("/home/xiongguo/biancheng/ceshi1/Mysql:","xgs2");
my ($statement) = 'select * from tab_fileinfo where filepath = "$fileinfos[0]" and filename = "$fileinfos[1]"' ;
steptodream 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xiaocai0001 的回复:]

ls -alRt | grep -v '^$'
[/Quote]
我都没想到直接在shell命令给过滤掉
脑袋太死了 哎
xiaocai0001 2010-11-02
  • 打赏
  • 举报
回复
ls -alRt | grep -v '^$'
steptodream 2010-11-02
  • 打赏
  • 举报
回复

#!/usr/bin/perl -w
use strict;
my @result=`ls -alRt`;
foreach(@result){
if($_ =~ /^$/){
next;
}
print $_;
}
xgxgxiong 2010-11-02
  • 打赏
  • 举报
回复
不好意思 没有分了 呵呵 下次多给点 谢谢两位

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧