Hi,
I'm trying to do a function that load all the jobs from the printers on systems
(Unix), and this
function returns a hash that has the printer name, the number of jobs and an array
that got
another hash with the names of job, owner jobs, date of the job.
I thinks something like this:
my %hash = ( printer_name => 'PRINTER NAME',
n_jobs => 'NUMBER OF JOBS',
jobs_name => [EMAIL PROTECTED],
)
where @jobs = a hash with job_name, job_owner and job_date
so i make this code:
_BEGIN_
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
sub lst_job{
my $printer = shift;
my @lpstat = `lpstat -P $printer`;
my %job;
my @jobs;
foreach (@lpstat){
if(/^$printer\-(\d+)\s+(\w+)\s+(\d+)\s+\w+\s(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2})/){
$job{job_name} = sprintf("d%05d-001",$1);
$job{job_owner} = $2;
$job{job_date} = $4;
}
push(@jobs,\%job);
}
my %printer = ( printer_name => $printer, #printer name
n_jobs => scalar @jobs, #number of jobs in the printer
jobs_name => [EMAIL PROTECTED], #the name, owner
and date
);
return %printer;
}
my %printers_job = lst_job("HP4100V");
printf "\nThe printer %s got %3d
jobs\n",$printers_job{printer_name},$printers_job{n_jobs};
print Dumper @printers_job{jobs_name} ;
foreach(@printers_job{jobs_name}){
print [EMAIL PROTECTED]>[1]}->{job_name};
print [EMAIL PROTECTED]>[1]}->{job_owner};
print "\n";
}
_END_
The problem is that i can list all the jobs of a printer.
this is the Dumper() result:
_RESULT_
The printer HP4100V got 18 jobs
$VAR1 = [
{
'job_owner' => 'rodza',
'job_date' => '01 Jul 2004 21:39:21',
'job_name' => 'd00026-001'
},
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0],
$VAR1->[0]
];
_END_RESULT
What is wrong?
Thank you.
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>