Rod Za <[EMAIL PROTECTED]> wrote:
: 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;
%job is only needed inside the 'if' block inside the
loop.
: my @jobs;
: foreach (@lpstat){
:
: if(/^$printer\-(\d+)\s+(\w+)\s+(\d+)\s+\w+\s(\d+\s\w+\s\d+\s\d
my %job;
: {2}:\d{2}:\d{2})/){ $job{job_name} =
: sprintf("d%05d-001",$1); $job{job_owner} = $2;
: $job{job_date} = $4;
: }
: push(@jobs,\%job);
We really don't need %job at all:
my @jobs;
foreach ( @lpstat ) {
next unless
/^
\Q$printer\E-
(\d+)\s+
(\w+)\s+\d+\s+\w+\s
(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2})
/ox;
push @jobs, {
job_name => sprintf 'd%05d-001', $1,
job_owner => $2,
job_date => $3,
};
}
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>