[p4perl] Return of some P4Perl API commands are either a HashRef or an ArrayRef of Hashes

Eleftherios.Kororos at symbian.com Eleftherios.Kororos at symbian.com
Wed Apr 13 08:44:04 PDT 2005


Hi all,

I recently came accros an issue that I am not sure if it is intended 
behaviour or not. If it is I would like to know if there are any ways 
around it. Here is the problem:

I have a p4 object as a memeber variable of another object (in this 
example $self). 
My p4 object is initialised correctly.
When I execute the following call:

my $openedFiles = $self->{p4}->Opened();

I get either 1 hash reference back, something like this:

$openedFiles->{action}
$openedFiles->{change}
$openedFiles->{client}
$openedFiles->{clientFile}
$openedFiles->{deoptFile}
....

However, if I have more than one files opened, then I get back a reference 
to an array of hashes. Something like this:

$openedFiles->[0]->{action}
$openedFiles->[0]->{change}
$openedFiles->[0]->{client}
....

$openedFiles->[1]->{action}
$openedFiles->[1]->{change}
$openedFiles->[1]->{client}
....

My problem is that if I want to process the returned $openedFiles variable 
I would typically do something like this:

foreach my $file (@{$openedFiles})
    {
        if (($file->{action} eq "integrate") || ($file->{action} eq 
"edit"))
        {
           #do things here for integrated and edited files
        }
    }

However, if I get back only a hashref this will result to a 
compiler/parser error with the following message:

Not an ARRAY reference at 
P:/intra/PR/users/eleftheriosk/integration_dev/submissionAutomation/Pull_Integrations/Checks/Dummy.pm 
line 91.

Also note that since I get back a reference anyway (which is a reference 
to either an array or to a hash) I can't find any way to check for the 
referenced type. I have tried the following:

my $tempOpened;
if (defined @{$p4Opened})
{
    $tempOpened = $p4Opened;
}
else
{
    $tempOpened = [$p4Opened];
}

but this only caused the compiler error to be reported earlier on in the 
program. 

How am I supposed to hadle this situation?

Regards, 

Terry Kororos
Integration Engineer
W: 0207 154 1519
M: 07747 065833
Symbian UK Ltd. 


-----------------------------------------
**********************************************************************
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London,  SE1 8HP, UK. This message is intended only for use by
the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not disseminate,
copy or take any action in reliance on it. If you have received this
message in error please notify postmaster at symbian.com and delete the
message and any attachments accompanying it immediately. Neither Symbian
nor any of its subsidiaries accepts liability for any corruption,
interception, amendment, tampering or viruses occurring to this message in
transit or for any message sent by its employees which is not in compliance
with Symbian corporate policy.
**********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/p4perl/attachments/20050413/a3c515c4/attachment-0001.html>


More information about the p4perl mailing list