RE: [cciug] Perl Help (a new problem)

From: Ted Jardine (ted.jardine@aspentech.com)
Date: Sun Jan 30 2000 - 00:26:01 EST


Sorry, that qw() was a typo. As Wolfgang so aptly put it, qx() is the
choice to make. Regret I don't understand the comment about chomp() --
probably since I always use it. If the string doesn't have <CR> or <LF>
then the output from chomp is the same as the input. I'm not questioning
that it is good practice to use chomp(), just that it is NOT mandatory so
long as you know what you are doing (which is the case all of the time
anyway). I think Wolfgang and I are in agreement far more than not, so I'll
step back into my office now :-).

Ted
______________
T. J. Jardine (Ted)
Sr. SCM Administrator
Aspen Technology, Inc.
19204 North Creek Parkway, #104
Bothell, WA 98011 USA Avocation:
Voice: 1.425.492.2272 Flight Instructor,
FAX: 1.425.492.2125 Airplanes & Instruments
E-mail: mailto:ted.jardine@aspentech.com "Keep the pointy end forward,
URL: http://www.aspentech.com the dirty side down."

-----Original Message-----
From: Wolfgang Laun [mailto:Wolfgang.Laun@alcatel.at
Sent: Saturday, January 29, 2000 01:44
To: Ted Jardine
Cc: 'Shanks, Jon'; CCIUG (E-mail)
Subject: Re: [cciug] Perl Help (a new problem)

A couple of remarks - please see below.

Ted Jardine wrote:

> Jon,
>
> The system call always returns the execution status (i.e., 0 for success,
> return code * 256 for other than success). What you want is to use the
> back-tick or qw() call:

The back-tick equivalent is qx() or qx{} or qx// (not qw).

>
>
> $Output = `$cmd`;
>
> I would also prefer the use of the string matching capability, especially
> since != is for numeric comparisons. Something like:
>
> if ( $Output =~ /inspected/ )
> { # code to handle inspected being present }
> else
> { # code to handle inspected not present }
>
> You might also want to get into the habit of using chomp() when you are
> about to handle a string returned from a system call. It benignly removes
> <CR> and <LF> characters that mark the end of a line. HTH.

To chomp is even a "must" if you want to use string comparison, e.g.

   if( $Output eq '"inspected"' ) ...

would always fail unless preceded by a chomp( $Output ). And (not knowing
what
else could be a valid attribute value - perhaps "to be inspected") I'd
prefer a
more constraining pattern:

   $Output =~ /^"inspected"$/

which also requires chomping.

Regards,
-Wolfgang

>
> Ted
> ______________
> ...
>
> -----Original Message-----
> From: Shanks, Jon [mailto:jshanks@logicon.com
> Sent: Friday, January 28, 2000 15:50
> To: CCIUG (E-mail)
> Subject: [cciug] Perl Help (a new problem)
>
> Hello all,
>
> I have been working on putting something in place here for a few days now.
I
> had a previous related issue called "Trigger help needed". Wolfgang Laun
got
> me on the path I needed to be on, but now I need help with the specific
> syntax in Perl.
>
> Basically what I am trying to do (which was my original issue) is have a
> trigger that fires upon checkin for all files. The corresponding script
> would check the attribute value on the file. If the attribute is set to
> "inspected" then the script would return 1 so that the checkin would fail.
> He is the script so far
>
> $ACCEPT=0;
> $REJECT=1;
> $CLEARCASE_PN = $ENV{ "CLEARCASE_PN" } . '@@';
>
> $cmd="cleartool describe -s -aattr Status $CLEARCASE_PN";
> print STDERR $cmd , "\n\n";
>
> if (system($cmd) != "\"inspected\"") {
> print STDERR "Accepted\n";
> exit $ACCEPT;
> }
> else {
> print STDERR "Rejected\n";
> exit $REJECT;
> }
>
> The "$CLEARCASE_PN = $ENV{ "CLEARCASE_PN" } . '@@';" line get me the file
> name with the @@ at the end (I couldn't find an EV that would give me
this)

Within triggers, you should be able to use $ENV{"CLEARCASE_XN_SFX"} to give
you
the "extended naming symbol". (But I wouldn't worry too much over that.)

>
> which is needed to check for an attribute set on the element instead of on
a
> version.
>
> My problem is that the system($cmd) call doesn't return the actual
attribute
> value. When I check that value I get 0 no matter if the attribute is set
on
> the file or not. How do I go about getting the actual attribute value
> returned so that my if statement will work? Is there a better way? Please
> help.
>
> Thanks!
>
> ~~~~~~~~~~~~~~~~~~~~~~~
> Jon Shanks
> Sr. CM Analyst
> Logicon Advanced Technology
> Colorado Springs, CO
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



This archive was generated by hypermail 2b29 : Sun May 06 2001 - 00:22:41 EDT