I am going to take a different aproach than every one else, although a did see how %ENV can be very helpfully.

Warning: Apache Head Talking
Traditionally, web servers allow users to host web 'sites' by giving them a directory that is publicly accessible, usually named 'public_html' - looks like yours is called 'web'. I am going to assume the rest (fingers crossed).

What I don't understand is why you want to use the tr/// or even the s/// operators (or substr or split . . .) to derive the two paths. There is nothing wrong with simply 'hard coding' this kind of data - it's not difficult to change, and you don't need to waste CPU time (albeit extremely minimal) doing it.

For example, you know that the disk path is:

$disk_path = '/home/sites/site18/users/rjoseph/web/';
and the URL path is probably:
$url_path = 'http://www.your_box.com/~rjoseph/';
Notice that 'web' is not included, and a tilde is added to the user name.

If you wanted to make this portable across different users of the same box, grab the user's name from %ENV:

$disk_path = '/home/sites/site18/users/' . $ENV{USER} . '/web/'; $url_path = 'http://www.your_box.com/~' . $ENV{USER} . '/';
You can always get to the images by using:
$img_path = $url_path . 'images/';

And by no means am I saying that you should disregard what everybody before me posted. On the contrary, they are showing you many different ways of using regular expressions, string operations, and array operations to 'munge' data. Practice them. :)

Jeff

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: Stripping parts of paths from directory names by jeffa
in thread Stripping parts of paths from directory names by r.joseph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.