Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Right then. I have the Printer module installed, and I am now trying to use it, with the following code:
use Printer; my $prn = new Printer('linux' => 'lp', 'MSWin32' => 'LPT1' ); my %data = $prn->list_printers; print $data{name}; print $data{port};
The result of this is ARRAY(blah_address)ARRAY(blah_address2), which I know is a reference to an array. I try to get this data by adding
my @list = \$data{name}; print @list;
but this gives me SCALAR(blah_address3). Aaaargghh!!! What's going on? All I want is the data!

Also, how do I poll a network for available printers?

Any help would be much appreciated

Alex.

Replies are listed 'Best First'.
Re: ok, still tryna print!
by Ovid (Cardinal) on Aug 28, 2002 at 15:59 UTC

    Reading through this module's documentation clarifies what's going on.

    %printers = list_printers().

    This returns a hash of arrays listing all available printers.

    To get the arrays out of there, try this:

    my @printers = @{ $data{name} }; my @ports = @{ $data{port} };

    Someone else will have to tackle the "poll a network" part of your question, though.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: ok, still tryna print!
by krisahoch (Deacon) on Aug 28, 2002 at 15:58 UTC

    Alex,

    Try this

    use Printer; use Data::Dumper; my $prn = new Printer('linux' => 'lp', 'MSWin32' => 'LPT1' ); my %data = $prn->list_printers; print Dumper %data;
    That should tell you what is stored in the hash, and give you the means to figure problems like this out in the future

    Data::Dumper has been an valuable tool for me.

    Kristofer A. Hoch