Fw: [p4perl] sync problems
Tony Smith
tony at smee.org
Mon Mar 14 10:15:53 PST 2005
On Monday 14 March 2005 17:09, Roger Day wrote:
> It's the same as before, except now:
>
> $#warnings == -1
>
> Roger
How's 'warnings' declared? $# operates directly on an array, not on a
reference to an array. i.e.
@warnings;
printf( "length = %d\n", $#warnings );
produces:
length = 0
But:
$warnings = $p4->Errors();
printf( "length = %d\n", $#warnings );
produces:
length = -1
Look familiar? In P4Perl it might look something like this:
#!/usr/bin/perl
use P4;
my $p4 = new P4;
my $errors = $p4->Errors();
my $warnings = $p4->Warnings();
printf( "%d (%d) errors\n", $#errors, $p4->ErrorCount() );
printf( "%d (%d) warnings\n", $#warnings, $p4->WarningCount() );
and this produces:
-1 (0) errors
-1 (0) warnings
This is because the $# operator is looking for @errors and @warnings, neither
of which have been defined. All brought to you through the joy of perl's
context-awareness....
If you make sure that @warnings and @errors are declared as arrays:
#!/usr/bin/perl
use P4;
my $p4 = new P4;
my @errors = $p4->Errors();
my @warnings = $p4->Warnings();
printf( "%d (%d) errors\n", $#errors, $p4->ErrorCount() );
printf( "%d (%d) warnings\n", $#warnings, $p4->WarningCount() );
You get:
0 (0) errors
0 (0) warnings
which is what you'd expect.
Tony
More information about the p4perl
mailing list