[p4] perl trigger

David Alban dalban at stubhub.com
Fri Nov 17 09:54:32 PST 2006


> You've got an operator precedence problem there.  Change to this:
> 
>    @FILES = `ls -l /perforce/triggers` or die("Bombed");
> 
> Or this:
> 
>   (@FILES = `ls -l /perforce/triggers`) || die("Bombed");

There is no operator precedence problem in either statement. 
Changing from the first statement above to the second does not change
the behavior of the code.

Because the "or" operator's precedence is the lowest of all perl
operators (see precedence table in perlop man page, and compare "or"
with "||"), or'ing is performed after assignment in the first
statement.  So the two statements above cause the program to behave
in exactly the same way.

However, there is a problem with both statements above in that they
don't examine the true status of the command executed in the backticks.
>From the perlvar man page:

  $?
     The status returned by the last pipe close, backtick (``) com-
     mand, successful call to wait() or waitpid(), or from the sys-
     tem() operator.  This is just the 16-bit status word returned
     by the wait() system call (or else is made up to look like it).
     Thus, the exit value of the subprocess is really ("$? >> 8"),
     and "$? & 127" gives which signal, if any, the process died
     from, and "$? & 128" reports whether there was a core dump.
     (Mnemonic: similar to sh and ksh.)

The following examines the true status of the ls command.

  @FILES = qx{ ls -l /perforce/triggers };
  my $status = $? >> 8;
  $status != 0 and die("Bombed");



David



-----Original Message-----
From: perforce-user-bounces at perforce.com on behalf of Ken.Williams at thomson.com
Sent: Thu 11/16/2006 11:16 AM
To: robertm at bioware.com; perforce-user at perforce.com
Subject: Re: [p4] perl trigger
 
Hi Rob,

You've got an operator precedence problem there.  Change to this:

   @FILES = `ls -l /perforce/triggers` or die("Bombed");

Or this:

  (@FILES = `ls -l /perforce/triggers`) || die("Bombed");

 -Ken

> -----Original Message-----
> From: perforce-user-bounces at perforce.com 
> [mailto:perforce-user-bounces at perforce.com] On Behalf Of 
> Robert McKenna
> Sent: Wednesday, November 15, 2006 4:53 PM
> To: perforce-user at perforce.com
> Subject: [p4] perl trigger
> 
> Hi 
> 
> I'm having a problem with a trigger which runs fine unless I try to
> execute a command using back ticks or system. The following is a very
> simple trigger I've been using for testing and which fails on the line
> @FILES = `ls -l /perforce/triggers`;. The trigger succeeds if 
> this line
> is replaced with a static assignment to @FILES. "Die" 
> produces no output
> in the validation failure message. 
> 
>  
> 
> #!/usr/bin/perl
> 
> @FILES = `ls -l /perforce/triggers` || die("Bombed");
> 
> foreach $FILE (@FILES) {
> 
>   $test = $FILE;
> 
> } 
> 
>  
> 
> The entry in the triggers table is this.
> 
>  
> 
> simple change-submit //test/perforce/robertm/triggers/CookedXenon/...
> "/usr/bin/perl /perforce/triggers/simple.pl 2>&1"
> 
>  
> 
> Any thoughts would be welcome.
> 
>  
> 
> Rob McKenna
> 
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
> 

_______________________________________________
perforce-user mailing list  -  perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user









More information about the perforce-user mailing list