Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

General tips for Unix to Windows script migration?

by Bukowski (Deacon)
on Jun 27, 2002 at 09:25 UTC ( #177664=perlquestion: print w/ replies, xml ) Need Help??
Bukowski has asked for the wisdom of the Perl Monks concerning the following question:

Hello PerlMonks! I am in the midst of writing (for me) quite a large piece of code. My development platforms are Linux and Solaris. However I would like to release this code some day on an unsuspecting world - and that world generally runs Windows.

I know of Activestate and Cygwin and other things that should make my life easier, but what general considerations are there for porting code like this? I know Apache and MySQL are now available for Windows (and what I am working on requires this) but do LWP, DBI, etc work 'as expected' on Windows platforms?

Can anyone point out any potential pitfalls I might encounter? Or am I working myself up into a lather over nothing much?

I've never attempted to write any code under Windows, so I am proceeding with trepidation...

Many humble thanks in advance for your wisdom

Bukowski - aka Dan (
"Coffee for the mind, Pizza for the body, Sushi for the soul" -Userfriendly

Comment on General tips for Unix to Windows script migration?
Re: General tips for Unix to Windows script migration?
by Zaxo (Archbishop) on Jun 27, 2002 at 09:47 UTC

    For the most basic level, see perldoc perlport.

    Database requirements are smoothed over a lot by use DBI; which allows the connection string to absorb many platform differences.

    Pure Perl modules like LWP will work right out of the box, for the most part.

    After Compline,

Re: General tips for Unix to Windows script migration?
by kodo (Hermit) on Jun 27, 2002 at 09:57 UTC
    I've been working on some scripts that had to work on both, linux and windows.

    I've used some DBI, LWP and other default-modules like SMTP::Sendmail etc. and didn't have any trouble with using them on a NT-Box & Linux/HP-Ux.
    You could get in trouble because of the different styles of pathes used in win/dos and *nix-systems. Like on a win-box an absolute path could be C:/home/giant while it's just /home/giant on *nix for example. I've seen quite lots of scripts that use different regexprs on pathes, especially CGI-Scripts, that's where you have to be careful I think.
    Also different on Win-Systems can be output made to console and the way the interpreter is used when doing perl -nle 'print if /test/' <file> it would be perl -nle "print if /test" <file> in windows. Another thing you have to look at is the newline-problem when copying data between these OSes, it happened that I forgot to set the right ftp-type etc and then had lots of ^Ms at the end of each line.

    You should also have a look at Perl Port from Perldoc, where you find lots of infos on making your perlcode portable. If you are looking for a good distribution I would suggest you Active Perl, there are lots of Prebuild Modules available for this one.

Re: General tips for Unix to Windows script migration?
by krazken (Scribe) on Jun 27, 2002 at 13:42 UTC
    Big pain in the neck for me was that on *NIX machines you could do:
    print "Hello\n";
    and everything works just dandy. Where as if you run the same code with say ActiveState, you will actually get an extra \r\n at the end of your print statement. So from a formatting perspective, keep that in mind...I am sure there is probably a way to get around it, but I am lazy, so I just change it to
    print "Hello";
    and it works the same. Just something to keep in mind! later krazken
      Define "extra"? DOS/Win32 newlines are different, but when you write something like this:
      print "line one\n"; print "line two\n";
      You should not get double-spaced output. There shouldn't be any "extra" newlines inserted here.

      You may, however, be seeing a trailing newline at the termination of your script. This is added by the Win32 command prompt. Even typing 'rem' will give you an empty line before showing the next prompt.

Re: General tips for Unix to Windows script migration?
by newrisedesigns (Curate) on Jun 27, 2002 at 19:25 UTC

    There aren't many pitfalls. Any modules that you might encounter that you have doubts about can be checked against testing information.

    The "\n" character cleanly prints CRLF. So you don't need to change your previous code. Perl is smart like that.

    Windows 9x is less reliable than NT flavors, but that's just my observation.

    Quick and Dirty newline fixer-uper (there's more than one better way to do this:)

    #!/usr/bin/perl use strict 'vars'; use vars qw( @stuff $i @ARGV $fh ); $/ = undef; if (-e "$ARGV[0]"){ open ($fh, "+>>$ARGV[0]"); seek $fh,0,0; @stuff = <$fh>; foreach (@stuff){ $_ =~ s/\r/\n/mig; } seek $fh,0,0; truncate $fh,0; print $fh @stuff; close $fh; print "Done.\n"; } else{ print "Select a file that's actually there.\n"; }

    Hope this helps.

    John J Reiser

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://177664]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2014-10-31 19:27 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (223 votes), past polls