Ged,

You are very entertaining. The code in question is also known as a combined
copy and substitution.

>Beware if you haven't got /src on the end of your source directory!

If you don't have a match with the string or regexp , you'll just get a straight copy.


Ed

   X-Authentication-Warning: C2H5OH.jubileegroup.co.uk: ged owned process doing -bs
   Date: Sat, 15 Jan 2000 00:00:37 +0000 (GMT)
   From: "G.W. Haywood" <[EMAIL PROTECTED]>
   Content-Type: TEXT/PLAIN; charset=US-ASCII
   Sender: [EMAIL PROTECTED]
   Precedence: bulk

   Hi there,

   On 14 Jan 2000, William P. McGonigle wrote:

   > Can someone explain what APACHE_ROOT is meant to be?  I'm assuming
   > it's somehow different thatn APACHE_SRC (which I'm defining).

   The expression

   ($APACHE_ROOT = $APACHE_SRC) =~ s,/src/?$,,;

   sets the scalar $APACHE_ROOT to be equal to the scalar $APACHE_SRC and
   then chops off any "/src" or "/src/" from the end of it.  
   

   The =~ binding operator (p27) tells perl to do the substitution
   s,/src/?$,, to the thing on left hand side of its expression.

   The parentheses (p77) mean the thing in them is a term, which has the
   highest precedence in perl so the assignment has to be done first.

   The substitution then has to be done on the result, $APACHE_ROOT and
   not $APACHE_SRC, er, obviously.

   The three commas are quotes (p41) for a substitution, presumably
   chosen because they can't easily appear in a filename.

   The pattern to match is

   /src/?$

   The question mark is a quantifier (p63), it says we can have 0 or 1
   trailing slash in the pattern we match - it's trailing at the end of
   a string because of the $ (p62).

   If our string matches, the matching bit is replaced with the bit
   between the second and third commas.  There's nothing between the
   second and third commas, so it's replaced with nothing.  Have a look
   at pages 72 to 74 especially for more about the s/// construct.

   The page numbers are from the Camel Book, second edition.  I keep it
   on my desk at all times, it stops my papers blowing around.  You will
   help yourself a lot with these things if you read chapters one and two
   five or six times this year as a kind of a penance.

   So if

   $APACHE_SRC eq  "/usr/local/apache/src/"

   or

   $APACHE_SRC eq  "/usr/local/apache/src"

   then

   $APACHE_ROOT eq "/usr/local/apache"

   after the substitution.

   I just *love* Perl's pattern matching!

   73,
   Ged.

Reply via email to