我正在尝试使用Net:: CUPS ->getDestinations()来获取CUPS中配置的打印机名称列表。
这样的一个简短的演示程序
#!/usr/bin/perl
use strict;
use warnings;
use Net::CUPS;
my $cups = Net::CUPS->new();
my @prts = $cups->getDestinations();
foreach my $printer (@prts) {
print "$printer\n";
}
exit;输出为
Net::CUPS::Destination=SCALAR(0x1e13bb0)
Net::CUPS::Destination=SCALAR(0x1e13bf8)
Net::CUPS::Destination=SCALAR(0x1e13c88)
Net::CUPS::Destination=SCALAR(0x1e13d18)
Net::CUPS::Destination=SCALAR(0x1e13d00)
Net::CUPS::Destination=SCALAR(0x1e4c9c8)我期待打印机名称,或一些东西,我可以传递给另一个函数,以获得打印机名称。我似乎把文档的这一部分解释错了。
getDestinations
my @printers = $cups->getDestinations();
This method will return an array of destinations currently configured on the cups server.有人知道如何使用Net::CUPS模块在CUPS中配置打印机列表吗?
发布于 2015-12-07 10:06:02
多亏了阿罗内什·辛格( Arunesh Singh ),稍微改变一下前程循环才是解决方案。现在我意识到getDestinations()正在返回一个对象数组。
#!/usr/bin/perl
use strict;
use warnings;
use Net::CUPS;
my $cups = Net::CUPS->new();
my @prts = $cups->getDestinations();
foreach my $printer (@prts) {
my $name = $printer->getName();
print "$name\n";
}
exit;https://stackoverflow.com/questions/34129612
复制相似问题