Question on Perl Script to get queue names

I have this perl script that I found on the list but I have an error when I run it: (my apologies if this a perl error, should find a perl list and post it there)

#!/usr/bin/perl

use lib “/var/lib/rt3”;use lib “/etc/rt3”;

package RT;

use strict;use warnings;use RT;use RT::Ticket;use RT::Tickets;use RT::CurrentUser;use RT::Queue;use RT::Transactions;use RT::Users;use RT::Groups;use RT::Principal;use DBI;use RT::Interface::CLI qw (CleanEnv GetCurrentUser);

Load the RT configurationRT::LoadConfig();# Initialiaze RTRT::Init();

#-------------------------------Gets current user name:my $user = RT::User->new($RT::SystemUser);print $user;

#-------------------------------Gets queue namesmy $queue_id = 10;my $queue_obj = RT::Queue->new( $session{‘CurrentUser’} );$queue_obj->Load( $queue_id );my $queue_name = $queue_obj->Name;print $queue_name;
----------------------------Output----------------------------
[root@test Desktop]# ./CF.pmGlobal symbol “%session” requires explicit package name at ./CF.pm line 40.Execution of ./CF.pm aborted due to compilation errors.[root@test Desktop]#

I have no clue as to what explicit package is missing:

Any ideas will be greatly appreciated…

Carlos

Play free games, earn tickets, get cool prizes! Join Live Search Club.
http://club.live.com/home.aspx?icid=CLUB_wlmailtextlink

At Wednesday 6/27/2007 11:08 AM, Carlos Ramon Lopez Midence wrote:

I have this perl script that I found on the list but I have an error
when I run it: (my apologies if this a perl error, should find a
perl list and post it there)

use DBI;
use RT::Interface::CLI qw (CleanEnv GetCurrentUser);

Load the RT configuration

RT::LoadConfig();

Initialiaze RT

RT::Init();

#-------------------------------Gets current user name:
my $user = RT::User->new($RT::SystemUser);
print $user;

#-------------------------------Gets queue names
my $queue_id = 10;
my $queue_obj = RT::Queue->new( $session{‘CurrentUser’} );

Carlos,

This is a Perl error - you’re referring to a variable called
%session, but you haven’t declared it. I’m guessing you got
this piece of code from the web app, which makes %session available
to you, and already has the current user object stored in it.

What you can do is this:

my $current_user = GetCurrentUser();

and then use $current user instead of $session{‘CurrentUser’}

OR - you could use RT::SystemUser instead of $session{‘CurrentUser’}

OR - you could load $user and use that.

Steve

Not sure if this will work but it might.

#!/usr/bin/perl

use warnings;
use strict;
use lib ‘/path/to/rt/lib/’;
use lib ‘/path/to/rt/local/lib/’;
use RT;
use RT::Queues;

my $queues = new RT::Queues(RT::SystemUser);
foreach my $queue ($queues->Next) {
print $queue->Name . “\n”;
}

exit;
Keep up with my goings on at http://theillien.blogspot.com

Carlos Ramon Lopez Midence wrote:

Hello, Carlos!

I don’t really sure if you need to use RT::Interface::CLI, you could have tried to eliminate it.
A problem with %session might be caused by your use of $session{ ‘CurrentUser’ }, try $RT::SystemUser instead.

Good luck!-----Original Message-----
From: Carlos Ramon Lopez Midence caralomi@hotmail.com
To: “rt-users@lists.bestpractical.comrt-users@lists.bestpractical.com
Date: Wed, 27 Jun 2007 11:08:32 -0400
Subject: [rt-users] Question on Perl Script to get queue names

I have this perl script that I found on the list but I have an error when I run it: (my apologies if this a perl error, should find a perl list and post it there)

#!/usr/bin/perl

use lib “/var/lib/rt3”;use lib “/etc/rt3”;

package RT;

use strict;use warnings;use RT;use RT::Ticket;use RT::Tickets;use RT::CurrentUser;use RT::Queue;use RT::Transactions;use RT::Users;use RT::Groups;use RT::Principal;use DBI;use RT::Interface::CLI qw (CleanEnv GetCurrentUser);

Load the RT configurationRT::LoadConfig();# Initialiaze RTRT::Init();

#-------------------------------Gets current user name:my $user = RT::User->new($RT::SystemUser);print $user;

#-------------------------------Gets queue namesmy $queue_id = 10;my $queue_obj = RT::Queue->new( $session{‘CurrentUser’} );$queue_obj->Load( $queue_id );my $queue_name = $queue_obj->Name;print $queue_name;
----------------------------Output----------------------------
[root@test Desktop]# ./CF.pmGlobal symbol “%session” requires explicit package name at ./CF.pm line 40.Execution of ./CF.pm aborted due to compilation errors.[root@test Desktop]#

I have no clue as to what explicit package is missing:

Any ideas will be greatly appreciated…

Carlos


Play free games, earn tickets, get cool prizes! Join Live Search Club.
http://club.live.com/home.aspx?icid=CLUB_wlmailtextlink


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com