Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://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 yourname@perl.me.uk? Just ask!!!

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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-30 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found