I normally do my development at home (Windows) and then upload my code and let it run on the server (Linux). It's a bit of a headache, but it works for me. To make this easier, all of my programs start with the following lines:
#!c:\perl\perl.exe
#!/usr/local/bin/perl
use strict;
When I upload the file to the server, I delete the first line and things seem to work. However, I'm now writing a script that has a data file. It seems that I need to refer to this file by an absolute path and I'm trying to implement this without requiring a lot of editing on the server-side version.
My current solution has me setting the path to the datafile as a global variable. The script checks the path to Perl and sets the value of the variable accordingly. Here's the code:
use strict;
use Config;
my $datafile = "";
if ( $Config{"perlpath"} =~ m/^c:/i ) {
$datafile = 'c:\work\perl\data';
} else {
$datafile = '/usr/svsingh/data';
}
That seems to work, but it looks like a kludge to me. Here are my questions:
- Other than putting the data file in the same directory as the script, is there a way around this issue? The directory structure for my ISP is quite funky, so I'd rather not use a relative path.
- Is there a better way than testing $Config{"perlpath"} to figure out which computer the script is running on and, therefore, where the data file is?
Thanks for your help.
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.