Rob Dixon wrote: > Mathew Snyder wrote: >> >> I have a problem printing out a hash. This is the script I'm working >> with: >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> use lib '/usr/local/rt-3.6.3/lib'; >> use lib '/usr/local/rt-3.6.3/local/lib'; >> use RT; >> use RT::Tickets; >> >> RT::LoadConfig(); >> RT::Init(); >> >> my $tix = new RT::Tickets(RT::SystemUser); >> $tix->FromSQL('Queue = "CustomerCare" OR Status = "resolved" OR Status >> = "open"'); >> >> my $timeworked = {}; >> my %env; >> >> while (my $ticket = $tix->Next) { >> my $customer = $ticket->FirstCustomFieldValue('Environment'); >> unless ($customer) {warn "warning" . $ticket->id. "no >> profile"; next} >> my $transactions = $ticket->Transactions; >> while (my $transaction = $transactions->Next) { >> next unless ($transaction->TimeTaken); >> $timeworked = >> $env{$transaction->Creator}{$transaction->TimeTaken}; >> print "Working on " . $ticket->id . "\n"; >> foreach my $key (keys %$env) { >> print $key . " -> " . $env{$key} . "\n"; >> } >> } >> >> } >> >> When I print the hash all I get is a reference. I can't seem to >> figure out how >> to get the actual contents. I've tried using \$, %$, %{$env} and >> %{env}. Some >> cause errors and some simply print out the reference. I'm not even >> sure I'm >> doing the "$timeworked = " line correctly. Can someone help me out >> with this >> please? > > Nothing is ever put into the %env hash. If it had contents you could > display them using > > foreach my $key (keys %env) { > printf "%s -> %s\n", $key, $env{$key}; > } > > but as it stands this will print nothing. I can't even work out what you > expect to > be in there, so I can't help you with the $timeworked assigment. Tell us > a little > bit more please. > > Rob >
I reworked it and about 90% of it works. #!/usr/bin/perl use warnings; use strict; use lib '/usr/local/rt-3.6.3/lib'; use lib '/usr/local/rt-3.6.3/local/lib'; use RT; use RT::Tickets; use RT::Users; RT::LoadConfig(); RT::Init(); my $tix = new RT::Tickets(RT::SystemUser); $tix->FromSQL('Queue = "CustomerCare" OR Status = "resolved" OR Status = "open"'); my %timeworked; while (my $ticket = $tix->Next) { my $customer = $ticket->FirstCustomFieldValue('Environment'); unless ($customer) {warn "warning" . $ticket->id. "no environment"; next} my %customer = ${customer}; my $transactions = $ticket->Transactions; while (my $transaction = $transactions->Next) { next unless ($transaction->TimeTaken); my %env = $transaction->Creator; my %env = ${env}; foreach my $cust (keys %customer) { foreach my $user (keys %env) { $env{$user} = $transaction->TimeTaken; foreach my $time ( keys %{$env{$user}} ) { $timeworked{$cust} = $env{$user}{$time}; } } } foreach my $key (keys %env) { print "Working on " . $ticket->id . " for $customer" . " -> " . $key . "\n"; foreach my $subkey (keys %timeworked) { print "Time worked for " . $subkey . " is " . $timeworked{$subkey} . "\n"; } } } } What I get now is the following: [Wed Mar 21 08:11:12 2007] [crit]: Can't use string ("5") as a HASH ref while "strict refs" in use at ./user_timesheet_new.pl line 34. (/usr/local/rt-3.6.3/lib/RT.pm:346) Can't use string ("5") as a HASH ref while "strict refs" in use at ./user_timesheet_new.pl line 34. I'm guessing "5" is a bit of data that is being pulled into the hash though I don't know for certain. I have no way of telling since rolling back the change I made to get to this point would leave me with nothing in that column anyway. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/