AFAIK, DOCUMENT_ROOT will only print out the absolute path to your, well, document root. This will not print the server's hostname. So I presume you have a directory called 'www.myhostname.com'. (E.g. /usr/local/www/www.myhostname.com/).
Of course you could use a DNS lookup (as suggested) on that portion of the path, but I tend to dislike that, if this script is only used on a few directories of yourself with fixed ip addresses. Each time you run the script, the DNS query will be performed and the script will have to wait for it's output. This can be time consuming, not to mention the bandwidth you waste ;)
I would suggest to simply use the IP address instead of the $ENV{DOCUMENT_ROOT} if possible, so use something like:
my $ip = "123.123.123.123";
chdir("$ip/dir1/dir2") || die "Can't open = $!\n";
If you have multiple directories (hostnames), you might want to create a hash with all the ip addresses you use.
%ip_address = ('www.myhostname.com','123.123.123.123','www.herhostname
+.net','456.456.456.456');
So you can look it up way faster ($ip_address{'www.myhostname.com'} will give "123.123.123.123").
This, of course, is handy for simple scripts with just a few hostnames and fixed ip addresses. If you have a lot, it can be time consuming to enter it all, so forget about bandwidth and use the DNS lookup, as suggested by others ;)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.