[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
Thu Apr 14 02:23:45 PDT 2005

Hi Tony,

excellent advice! I should had read the documentation a bit better :)

Thanks a lot,

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

Tony Smith <tony at smee.org> 
Sent by: p4perl-bounces at perforce.com
13/04/2005 21:06

Eleftherios.Kororos at symbian.com
p4perl at perforce.com
Re: [p4perl] Return of some P4Perl API commands are either a HashRef    or 
an ArrayRef of Hashes

Hi Terry

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

P4::Run() returns are defined thus:

     An array of results in array context.
     undef in scalar context if result set is empty.
     A scalar result in scalar context if only one result exists.
     An array ref in scalar context if more than one result exists.

So, if you always want an array of results to process, simply use array 

   my @openedFiles = $p4->Opened();

Hope that helps!

p4perl mailing list
p4perl at perforce.com

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/20050414/14c8c12f/attachment-0001.html>

More information about the p4perl mailing list