Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Cross platform coding advice

by Corion (Patriarch)
on Oct 08, 2005 at 06:38 UTC ( [id://498373]=note: print w/replies, xml ) Need Help??


in reply to Cross platform coding advice

It's very easy to develop on Windows for Linux, as long as you keep that in mind. Under Windows, mostly there are features lacking, like proper fork(), selectable filehandles and some other stuff, so if you follow what is outlined in perldoc perlport, you should be mostly going. The main problems are when you're interacting with the operating system, and that is mainly by opening files.

  • You should use all filenames in "unix notation", as Win32 understands the forward slash as path separator as well.
  • For temporary files, use File::Temp instead of hardcoding the filename
  • At the start of the program, change the directory to a known location. I often use the following snippet:
    use strict; use File::Basename; use lib 'lib'; # or maybe '/home/k_rajesh/perl5lib' chdir dirname $0;
  • Keep all additional modules for your program in a directory under your "main program directory". If your main program has to live in a web-accessible directory, I recommend to launch it through a shell script from there, as that will keep your Perl code clean and your modules out of the web accessible space:
    #!/bin/sh exec '/home/k_rajesh/perl_prog/prog.pl'

For installing modules on the Linux host, that is very easy as long as the modules are written in Perl, see A guide to installing modules for Win32, especially the "Manual install" section. In most cases, you can simply unpack the module distribution and copy all files into your application lib directory in the right directories.

Replies are listed 'Best First'.
Re^2: Cross platform coding advice
by nothingmuch (Priest) on Oct 08, 2005 at 15:54 UTC
    Don't use forward or backslashes, instead use File::Spec or Path::Class:
    use File::Spec; # could also use File::Spec::Functions my $file_name = File::Spec->catfile(File::Spec->updir, qw/foo bar.txt/ +); # "../foo/bar.txt" on unix # or use Path::Class; # these return Path::Class::File objects which can be used as strings # and also have some convenient methods ($file->open, etc) my $file_a = Path::Class->new()->parent->subdir("foo")->file("bar.txt" +); my $file_b = file(dir()->parent, "foo", "bar.txt');
    -nuffin
    zz zZ Z Z #!perl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-05-25 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found