免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sousi

perl问题请教 [复制链接]

论坛徽章:
0
发表于 2006-12-13 21:08 |显示全部楼层

回复 10楼 dajun 的帖子

我和你正好相反,我们公司不能上网。今天发帖是在家里休息来着。

论坛徽章:
0
发表于 2006-12-13 22:53 |显示全部楼层
先把汇编代码编译一把,然后分析error

论坛徽章:
0
发表于 2006-12-14 09:34 |显示全部楼层
solaris的grep好像不支持递归  grep -r  你如果shell熟就用shell,自己递归目录

论坛徽章:
0
发表于 2006-12-14 10:57 |显示全部楼层
个人感觉,这两个问题,对shell和perl同样不熟悉的情况下,shell解决起来更简单。
第一个问题无非是正则匹配,您的需求中需要用到的正则并不复杂,没必要用perl。
第二个问题用shell更简单,一句find+grep直接出来结果了。

论坛徽章:
0
发表于 2006-12-14 21:09 |显示全部楼层
顶一顶,特别是第二个任务,老板下周一要我交啊,谢谢!

论坛徽章:
0
发表于 2006-12-16 22:37 |显示全部楼层
总算有点眉目了,下面的代码实现了特定目录下所有文本文件中的特定字符:
#!/usr/bin/perl
use File::Find;
find(\&filefind,"/opt/checkpath/test");
sub filefind{
    my $findfile = $File::Find::name;
    if (-T $findfile){
       open(filehand,"$findfile");
       while ($line=<filehand>)
           { print "$findfile\n","$line\n" if $line=~/^homedsn/;
            }
       close(filehand);
       }
}

论坛徽章:
0
发表于 2006-12-18 14:19 |显示全部楼层
如何将系统调用返回的标准输出赋值给一个变量,比如:
system("ls -l $findfile | awk \'{print \$9,\$10,\$11}\'");
该命令的输出为:
  /dir/file -> /dir2/file
希望把这个字符串赋值给一个变量,好做进一步的比较匹配,谢谢大家帮忙!

论坛徽章:
0
发表于 2006-12-18 18:30 |显示全部楼层
大家伙给个提示啊~!谢谢!

论坛徽章:
0
发表于 2006-12-18 19:20 |显示全部楼层
原帖由 sousi 于 2006-12-18 14:19 发表
如何将系统调用返回的标准输出赋值给一个变量,比如:
system("ls -l $findfile | awk \'{print \$9,\$10,\$11}\'");
该命令的输出为:
  /dir/file -> /dir2/file
希望把这个字符串赋值给一个变 ...


Hi,

using backstick operator "`":
$studout = `YOUR_SHELL_CMD`:
or using open FH -| or |- method to get STDOUT

try again. --ulmer

论坛徽章:
0
发表于 2006-12-18 19:29 |显示全部楼层
原帖由 ulmer 于 2006-12-18 19:20 发表


Hi,

using backstick operator "`":
$studout = `YOUR_SHELL_CMD`:
or using open FH -| or |- method to get STDOUT

try again. --ulmer



你总算出马了,谢谢你的提示。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP