Mathew Snyder wrote:
Chad Kemp wrote:
Mathew,
try to test every condition going INTO the hash (or hashes) before
you actually assign a value to a key. as mentioned earlier, hashes must
be key/value pairs. the key will auto-vivify if a key is "new" but only
if a corresponding value accompanies it. when you assign values to all
of your hashes, check to see if that value is *defined*. when you try
to assign undefined values into a hash, you will get undesirable results.
you already know this, but just presenting it for the sake of
completeness... you need to ensure all of your KEYS are unique (unless
of course you want to overwrite the previous entry with the most
recent... last in, and all that :) ...
so now you have keys, and when you assign values to them, you need to
make sure it is defined, else store some arbitrary value in there that
you can test for later... like a scalar "empty" or something else that
is easily determined to NOT be useful data.
are you returning a hash from a method in another module? if so, try to
dereference it as soon as it is returned, storing it into a new lexical
hash and iterate through the lexical hash...
This is what I think will have to be done. How do I go about that? Would I use
something like \%environment = $ticket->FirstCustomFieldValue('Environment')?
What I've been trying to do is place the object into a hash and then iterate
through it assigning 0 to each key.
hope some of that helps.
i would include some code snips, but i am in the middle of a
construction project, and am pressed for time.
cheers
~CK
#!/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" AND Status = "open" AND Created <
"2007-03-03"');
my %environment;
my %timeworked;
my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;
while (my $ticket = $tix->Next) {
my $environment = $ticket->FirstCustomFieldValue('Environment');
unless ($environment) {
warn "warning" . $ticket->id. "no environment";
next
}
my $transactions = $ticket->Transactions;
while (my $transaction = $transactions->Next) {
next unless ($transaction->TimeTaken);
foreach my $user ($users->Next) {
if ($user = $transaction->Creator) {
$timeworked{$user} +=
$transaction->TimeTaken;
$environment{$environment} =
$timeworked{$user};
}
}
}
}
foreach my $env (sort keys %environment) {
print "\n" . $env . "\n";
print "--------------------\n";
foreach my $user (sort keys %timeworked) {
print $user . " -> " . $timeworked{$user} . "\n";
}
}
Mathew
Matthew,
* \%environment = $ticket->FirstCustomFieldValue('Environment')* is
actually CREATING a hash reference. and i think you are ending up with
a reference to a reference.
Try something like:
my $ref = $ticket->FirstCustomFieldValue('Environment');
my %hash = %$ref;
i have a program at work that i have custom packages defined and i am
passing it a Net::LDAP object (itself a hash)... performing some work,
and passing back a new hash... but what i actually get back is a hash
REF, so i have to dereference (as above) once i get it back... then i
can work on it.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/