I am having a problem with something simple. I need to pick out the length of the RT Ticket Subject, for the length of my table header, but I need to check the length in the for loop I am searching for tickets in.
You'll see what I mean in the below code. How can I pass the max subject length back out of the loop? I AM BEING DUMB!
#!/usr/bin/perl
use strict;
use warnings;
use Error qw(:try);
use RT::Client::REST;
use DateTime;
use Text::SimpleTable;
use Data::Dumper;
use List::Util qw( max );
my $user = '';
my $pass = '';
my $dt = DateTime->now;
my $ymd = $dt->clone->subtract( months => 1 )->ymd;
my @queues = qw/ xxxx /;
my $rt = RT::Client::REST->new(
server => 'http://xxxxx',
timeout => 30,
);
try {
$rt->login( username => $user, password => $pass );
}
catch RT::Client::REST::Exception with {
die "Problem logging in: ", shift->message;
};
try {
my $t = Text::SimpleTable->new(
[ 11, 'ID' ],
[ 25, 'Subject' ],
[ 30, 'Requestor' ],
[ 25, 'Created' ],
[ 25, 'Last Updated' ]
);
my @subj_len;
for my $queue (@queues) {
my @ids = $rt->search(
type => 'ticket',
query => "Created > '$ymd' AND Queue = '$queue'",
);
for my $id ( sort @ids ) {
my ($ticket) = $rt->show( type => 'ticket', id => $id );
push @subj_len, length $ticket->{Subject};
$t->row(
$ticket->{id}, $ticket->{Subject},
$ticket->{Requestors}, $ticket->{Created},
$ticket->{LastUpdated},
);
}
my $subj_max = max @subj_len;
print $subj_max, "\n";
print $t->draw;
}
}
catch RT::Client::REST::Exception with {
print "Something went wrong.", shift->message;
};
Thanks, Gavin.
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!