我需要检查Perl脚本中是否存在任何一组目录.目录以XXXX*YYY格式命名 - 我需要检查每个XXXX并输入if语句,如果为true.
在我的脚本中,我有两个变量$ monitor_location(包含被扫描的根目录的路径)和$ clientid(包含XXXX).
下面的代码片段已经扩展,以显示我正在做的更多内容.我有一个返回每个客户端ID的查询,然后我为所返回的每个记录循环并尝试计算该客户端ID使用的磁盘空间.
到目前为止我有以下代码(不起作用):
# loop for each client
while ( ($clientid, $email, $name, $max_record) = $query_handle1->fetchrow_array() )
{
# add leading zeroes to client ID if needed
$clientid=sprintf"%04s",$clientid;
# scan file system to check how much recording space has been used
if (-d "$monitor_location/$clientid\*") {
# there are some call recordings for this client
$str = `du -c $monitor_location/$clientid* | tail -n 1 2>/dev/null`;
$str =~ /^(\d+)/;
$client_recspace = $1;
print "Client $clientid has used $client_recspace of $max_record\n";
}
}
Run Code Online (Sandbox Code Playgroud)
要清楚,如果有任何以XXXX开头的文件夹,我想输入if语句.
希望这是有道理的!谢谢
您可以使用glob来扩展通配符:
for my $dir (grep -d, glob "$monitor_location/$clientid*") {
...
}
Run Code Online (Sandbox Code Playgroud)