Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

New Object and loops with Text:SimpleTable

by ghenry (Vicar)
on Oct 18, 2006 at 18:36 UTC ( #579166=perlquestion: print w/ replies, xml ) Need Help??
ghenry has asked for the wisdom of the Perl Monks concerning the following question:

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

Comment on New Object and loops with Text:SimpleTable
Download Code
Re: New Object and loops with Text:SimpleTable
by pgor (Beadle) on Oct 18, 2006 at 22:55 UTC
    Simply change the scope of $subj_max. Just before the for loop, declare
    my $subj_max = 0;
    and remove the 'my' from
    my $subj_max = max @subj_len;

      Of course. The key word being scope.

      Thanks.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://579166]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-07-31 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls