Home > Archive > PERL CGI Beginners > October 2005 > hardcoded paths
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Dermot Paikkos 2005-10-28, 7:55 am |
| Hi,
I am moving a site from once host to another. There are lots of
hardcoded fully qualified paths to the localhost (EG
http://myserver/cgi-bin/someprog.pl?name=val &
http://myserver/css/mystyle.css).
I am pretty sure this isn't good practise but I am not a bit lost as
to what are good alternatives. I don't want to make the same mistake
and have to do all this editing again next time the hardware changes.
Should I be trying to create a module with these paths in? Or is
there some other way?
Thanx.
Dp.
| |
| David Dorward 2005-10-28, 7:55 am |
| On Fri, Oct 28, 2005 at 10:28:20AM +0100, Dermot Paikkos wrote:
> I am moving a site from once host to another. There are lots of
> hardcoded fully qualified paths to the localhost
> I am pretty sure this isn't good practise but I am not a bit lost as
> to what are good alternatives.
Relative URLs?
--
David Dorward http://dorward.me.uk
| |
| Wiggins d'Anconia 2005-10-28, 6:55 pm |
| Dermot Paikkos wrote:
> Hi,
>
> I am moving a site from once host to another. There are lots of
> hardcoded fully qualified paths to the localhost (EG
> http://myserver/cgi-bin/someprog.pl?name=val &
> http://myserver/css/mystyle.css).
>
> I am pretty sure this isn't good practise but I am not a bit lost as
> to what are good alternatives. I don't want to make the same mistake
> and have to do all this editing again next time the hardware changes.
>
> Should I be trying to create a module with these paths in? Or is
> there some other way?
> Thanx.
> Dp.
>
>
Relative URLs as David mentioned would be good whereever they can be
used. The other option I use is to create a Setup.pm module that
contains constants for these things.
use constant CONFIG_URL_BASE => 'http://yoursite.com';
use constant CONFIG_URL_CGI_BASE => 'http://yoursite.com/cgi-bin';
Then you need to export those constants into the calling code. The only
bummer about using constants is that they don't interpolate inside
strings, but I have settled on using concatenation and prefer to have
the extra overhead to have the ease of changing all URLs on a site at once.
This also makes module code that generates links reusable across sites.
http://danconia.org
|
|
|
|
|