[p4perl] Problem Running P4Perl Based Triggers After LinuxSystemUpdate

Tony Smith tony at smee.org
Fri May 9 09:17:52 PDT 2008


Slightly late to the party as Peter's already solved it (thanks Peter!), but 
here's the full scoop:

Basically, the Run* methods return:

(a) a list if called in array context; otherwise,
(b) a reference to the array 

So, this is about Perl context: where the caller tells the called function 
what kind of results it wants (something I'm frankly quite disapproving of, 
but it's endemic in Perl).

So, the two examples relevant to this case are:

@results = $p4->RunJobs();	# RunJobs() returns a list
$results = $p4->RunJobs();	# RunJobs() returns an array reference

In the first example, RunJobs() returns a list, which is then assigned by Perl 
to the named array @results. Returning a list also enables things like:

	foreach $job ( $p4->RunJobs() )
	{
		...
	}

In the second example, RunJobs() knows that the caller is expecting a scalar 
result, so it returns a (scalar) reference to the result array.

Hope that helps clear it all up!

Tony


On Friday 09 May 2008 15:21:33 Scott Lavender wrote:
> Ah! This returns a reference to an array of hash table references....
> That's a mouth full.
>
> So, I was able to get at the Jobs using this version:
>
> # Try getting list of all Jobs
> my @jobs = $p4->RunJobs();
> if ( $#jobs >= 0 )
> {
>     foreach $job ( @jobs )
>     {
>         print "$job->{ 'Job' }\n";
>     }
> }
> else
> {
>     print "There are no jobs...\n";
> }
>
> Thanks.....Scott...
>
> -----Original Message-----
> From: Peter Prymmer [mailto:PPrymmer at factset.com]
> Sent: Friday, May 09, 2008 10:06 AM
> To: Scott Lavender
> Cc: p4perl at perforce.com; p4perl-bounces at perforce.com; Tony Smith
> Subject: Re: [p4perl] Problem Running P4Perl Based Triggers After
> LinuxSystemUpdate
>
> p4perl-bounces at perforce.com wrote on 05/09/2008 09:21:42 AM:
> > "Scott Lavender" <Scott.Lavender at visiprise.com>
> > Sent by: p4perl-bounces at perforce.com
> >
> > 05/09/2008 09:21 AM
> >
> > To
> >
> > "Peter Prymmer" <PPrymmer at factset.com>
> >
> > cc
> >
> > p4perl at perforce.com, Tony Smith <tony at smee.org>
> >
> > Subject
> >
> > Re: [p4perl] Problem Running P4Perl Based Triggers After
>
> LinuxSystemUpdate
>
> > This is usually how I do things with P4Perl. Usually these return a
> > scalar reference to an array or hash that can be dereferenced later.
> > Maybe Tony can set me straight... ;)
>
> If it is a scalar reference to an array (admittedly I should consult
> the docs to discern) then perhaps you intended to
> dereference the array when accessing it.  That is, instead of:
>
> my $jobs = $p4->RunJobs();
> if ( $#jobs >= 0 )
> {
>     foreach $job ( @jobs )
>     {
>         print "$job\n";
>     }
> }
> else
> {
>     print "There are no jobs...\n";
> }
>
> Perhaps you wanted to write (note the extra $jobs in two places below):
>
> my $jobs = $p4->RunJobs();
> if ( $#$jobs >= 0 )
> {
>     foreach $job ( @$jobs )
>     {
>         print "$job\n";
>     }
> }
> else
> {
>     print "There are no jobs...\n";
> }
>
> Peter Prymmer
>
> !DSPAM:48245da7119221970173131!




More information about the p4perl mailing list