fatherlyons has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am running a perl script off the back of a PHP script through Apache. The script uses the P4 module to perform some P4 commands. I'm getting a really strange problem though..Heres the bit of code I'm trying to run:
$command = "print"; $CL = shift; push @options, "-q", "$filename...\@$CL"; @info = $p4->Run( $command, @options ); @options = (); $errors = $p4->ErrorCount(); die "Errors occured when executing p4 print -q $filename...\@$CL\n" if + ($errors > 0); foreach my $element (@info) { $Components = $Components.$element; } @info = (); return $Components;
$CL is a 6 digit number which is passed to the function as an argument. The problem is, when I run this through Apache it doesn't return the $Components string. However, if I explicitly set the $CL to a number (i.e $CL = 565431;) it works fine!! The number is definitely being passed in correctly as the script runs fine as a standalone program and it isn't down to Perforce access rights either. Any ideas cos I'm all out!!! Cheers, DP

Replies are listed 'Best First'.
Re: Perl / Apache / P4 Problem
by Tanktalus (Canon) on Jul 06, 2005 at 12:55 UTC

    Never used P4, but how I'd approach the problem (after doing everything you said you're doing) is to insert some logging statements into the code to ensure that $CL is set properly, for example. One popular log module is Log::Log4Perl, although I find it quite heavy. Regardless, what you want to do is show what $CL is right after the shift, show what @options is, right after the push, $errors right before the die, and @info right before the foreach.

    Debugging tips aside, "$Components = $Components.$element" is easier said as "$Components .= $element". However, the entire foreach statement is easier said as "$Components = join '', @info". (I'm assuming $Components starts out empty - if that's not the case, change the = to .=)

    Also, I'm not sure why you're clearing out @options - usually @options would not be global, so it would get cleared at the end of the routine anyway. But that's really not that important. Just that if it's not needed, it's clutter. Same for @info.

Re: Perl / Apache / P4 Problem
by etcshadow (Priest) on Jul 06, 2005 at 13:44 UTC