tags:

views:

57

answers:

2

when I use the following command in command line it's giving list of non integrated change lists.

p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt

But when I use this command in a Perl script as below it's not giving output:

$cmd = system ("p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt");

The output message in commandline is some error as given below:

branch1, - all revision(s) already integrated.

The issue is because of the comma used between date1 and date2? How to use this command in a Perl script?

+7  A: 

This is why it is so important to turn on the strict and warnings pragmas. The string "@$date1" does not mean what you think it does. It is trying to dereference $data1 as a an array. Because strict isn't on it is treating the contents of $date1 as a symbolic reference. If you had turned on strict you would have seen an error message like:

Can't use string ("2010-08-30") as an ARRAY ref while "strict refs" in use at script.pl line 10.

You should probably say this instead:

system "p4 interchanges -t $branch1\@$date1,\@$date2 $branch2 > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}

You may also have a problem if you expect $branch1, $date1, etc. to be shell variables instead of Perl variables. In that case you should say:

system "p4 interchanges -t $ENV{branch1}\@$ENV{date1},\@$ENV{date2} $ENV{branch2} > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}
Chas. Owens
A: 

If you're going to be doing a lot of Perforce with Perl, try the P4Perl, which wraps Perforce in a Perl-native API.

Cribbing from the documentation, your system() call could be implemented as:

use P4;
my $p4 = new P4;
$p4->SetClient( $clientname );
$p4->SetPort ( $p4port );
$p4->SetPassword( $p4password );
$p4->Connect() or die( "Failed to connect to Perforce Server" );

my $c = $p4->Run( "interchanges", "-t", $branch1, "@".$date1, "@".$date2, $branch2 );

$c will contain an array reference with each of the unintegrated changelists.

Commodore Jaeger