Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear Master Monks,

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 Just ask!!!

In reply to New Object and loops with Text:SimpleTable by ghenry

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (6)
    As of 2020-07-03 16:46 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found