Programming with P4Perl

The following example shows how to connect to a Perforce server, run a p4 info command, and open a file for edit.

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 $info = $p4->Run( "info" );
$p4->RunEdit( "file.txt" );
die( "Failed to edit file.txt" )
  if $p4->ErrorCount()
  or $p4->WarningCount;

$p4->Disconnect();

Connecting to Perforce over SSL

Scripts written with P4Perl use any existing P4TRUST file present in their operating environment (by default, .p4trust in the home directory of the user that runs the script).

If the fingerprint returned by the server fails to match the one installed in the P4TRUST file associated with the script's run-time environment, your script will (and should!) fail to connect to the server.