Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: "Porting" scripts to Win32

by punkish (Priest)
on Feb 20, 2004 at 14:04 UTC ( [id://330538]=note: print w/replies, xml ) Need Help??


in reply to "Porting" scripts to Win32

I routinely use perl on a Win XP box at work (at home I run Mac OS X) so I can offer a few pointers.

Unfortunately, just like the different versions/vendors/flavors/variants of Unix, Windows directory layout also varies from OS version to version. But, it is mostly quite predictable. And most system directories can be addressed by variables. I have never used Windows system variables in perl scripts, but it would be interesting to see if they work... they are usually surrounded by % signs such as %TEMP% or %SYSTEM% etc.

The ~/.app-name is actually followed, but it is not OS mandated but application specific. Of course, directories or files starting with a . are not invisible.

On Win XP there is a convolutedly named "Documents and Settings" folder on the C root where such things get stored usually, and under that folder is also an Application Data (I think that is what it is called) folder where app specific detritus can be stored such as mozilla prefs, etc.

You don't really have to hack the registry as it is mostly for system specific things such as asscoiating all .pl or .plx extension files with the perl binary so you can actually run those files by double-clicking on them.

Most config files get stored under the Winnt directory and they usually end with the .ini suffix.

Hope some of this helps. But you definitely will have to explore the various versions of Windows to figure out if your scripts are going to be affected. Alternatively you could run a config script that asks the user a few questions and makes its settings, but most users are not likely to know what goes where. Or, you could just make up your own tmp directory, store stuff there, and blow it away when the script is done (or not, if you want the settings to persist).

Since I have never needed to mess with those kind of things, I have found that my scripts run mostly without any changes and without any problems (except for changing the shebang line, of course when moving from Mac OS X to Win and back. If I have to store anything, I usually create a directory under my scripts directory where I can write stuff.

Replies are listed 'Best First'.
Re: Re: "Porting" scripts to Win32
by meetraz (Hermit) on Feb 20, 2004 at 14:17 UTC
    I can't help but reply to some of this.

    %TEMP% and %SYSTEMROOT% will work only from the shell. To access these in perl, use $ENV{TEMP} and $ENV{SYSTEMROOT}.

    Yes, the "Appliation Data" directory under "Documentions and Settings" is the right thing to use for DATA if you're on Win2k or XP, but it doesn't exist on other versions of Windows. To play it safe, use the Win32::GetFolderPath() function, which will always return the proper path regardless of which OS you're on, what changes the network admin has made, or what the user's preferences are. (Try CSIDL_APPDATA or CSIDL_PERSONAL)

    The registry is NOT just for system-specific things. Almost Every application on your computer uses the registry to store its configuration info. It was designed to alleviate the problems of having thousands of configuration files scattered all over the machine, each with a different syntax.

    To summarize, DATA (like large files) should go in whatever path Win32::GetFolderPath() gives you, and CONFIG (like simple settings) should go in the registry.

    Most appliations do NOT use INI files under Winnt. This was common in the Windows 3.1 days, but not any more. The files there are only for legacy compatibility. (And "Winnt" doesn't even exist in the newer OSes like XP)

    </rant>

      I would just like to add that while you are correct that the registry "was designed to alleviate the problems of having thousands of configuration files scattered all over the machine, each with a different syntax", Microsoft has now realized that it's design did not accomplish that well. They have decided that application specific configuration files are a better approach. They recommend them for all .NET applications and it is how ASP.NET applications are configured (for features such as Authentication, Session State, Application Variables, etc). The config files are in an XML format and are easily parsed using classes in the "System.Configuration" namespace.

      In response to the OP: Most open source applications I have installed on my W2K box are ports of linux apps. They store their information in config files under "\Documents and Settings\username\appname\" or "\Documents and Settings\username\Application Data\appname\". Most people familiar with the linux apps ported to windows will expect one of those two methods.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://330538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-18 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found