http://qs321.pair.com?node_id=296981

svsingh has asked for the wisdom of the Perl Monks concerning the following question:

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:

  1. 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.
  2. 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.