下面是我的文件,我被delimeneter分隔条件,通过电子邮件将进一步发送 列表:Device1的|城|街| roadname |区域|状态|区域|国家| COUNTRYCODEperl的while循环不工作
________________________________________________
Device1|City|Street|roadname|region|state|area|country|countrycode
Device2|City|Street|roadname|region|state|area|country|countrycode
Device3|No data found
Device4|No data found
_________________________________________________
my $filename = '/tmp/list.txt';
open my $ifh, '<', $filename
or die "Cannot open '$file' for reading: $!";
local $/ = '';
my $filename = <$ifh>;
my @arr = split(/\|/, $filename , -1);
$Device = $arr[0];
$Region = $arr[2];
$State = $arr[3];
$area = $arr[10];
$country = $arr[19];
$logger->debug("$logid >> file information Device Name: $Device");
$logger->debug("$logid >> file information Region: $Region");
$logger->debug("$logid >> file information State: $State");
$logger->debug("$logid >> file information Area: $area");
$logger->debug("$logid >> file information Country: $country");
close($ifh);
我能够得到以下信息,但我的要求是每当它显示“找不到数据”时,将其分配给变量,例如..“模式”,我将通过电子邮件进一步发送。
$smtp->datasend("$Device1|$region|$state|$area|$country\n");
$smtp->datasend("$pattern\n");
感谢
你的问题真的不清楚。代码中没有while循环。 – Cfreak 2013-04-11 16:20:20
感谢您的回应..我已经尝试做下面的东西,但它不工作... $设备= $ ARR [0]; $ condition =“$ Device | No data found”; (<>){ if($ line =〜/ $ condition /){ print $ condition; $ pattern = $ condition } } – user28104 2013-04-11 16:26:22
请返回并修改您的问题以包含整个代码,而不仅仅是选中的部分。另外,**“不起作用”是什么意思?**“不起作用”是我们理解问题的不充分描述。当你尝试时发生了什么?你得到不正确的结果了吗?你有没有得到结果?如果结果不正确,是什么使它们不正确?你想要什么呢?你有没有得到任何正确的结果?如果是这样,他们是什么?不要让我们猜测。 – 2013-04-11 16:49:02