Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Writing common script for windows and unix..... Posted by Prakash_Radha on 25 Feb 2004 at 3:57 AM
hi, i want to know how to write scripts such that i can use them in both windows and unix.....

For example windows uses back-slash(\) whereas unix uses forward-slash(/) for specifying the path.....

Another example could be using commands such as fc and diff which are file comparison commands in UNIX and DOS respectively.....

Is there any way to specify that if the OS detected is Windows then use one script and if the OS specified is UNIX or Linux then use another script???

Thanks,
prakash.
Report
Re: Writing common script for windows and unix..... Posted by Jonathan on 25 Feb 2004 at 4:32 AM
: hi, i want to know how to write scripts such that i can use them in
: both windows and unix.....
:
Mostly, by avoiding stuff that doesn't work in both places.

: For example windows uses back-slash(\) whereas unix uses forward-
: slash(/) for specifying the path.....
:
I've generally found you can get away with using forward slashes on Windows and it won't complain. Especially if you're just using relative paths etc. You may be interested in a module called File::Spec.

: Another example could be using commands such as fc and diff which
: are file comparison commands in UNIX and DOS respectively.....
:
If you are going to be depending on external programs, you inherently risk cross-platform issues. It's often a good idea to see if you can manage a pure-Perl implementation. And remember to check out http://search.cpan.org/ as someone else may have done some of the hard work for you.

: Is there any way to specify that if the OS detected is Windows then
: use one script and if the OS specified is UNIX or Linux then use
: another script???
:
if ($^O =~ /MSWin32/) {
    # do Win32 stuff
} elsif ($^O =~ /linux/) {
    # do Linux stuff
# other checks
} else {
    # we have no idea - do something generic.
}


Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: Writing common script for windows and unix..... Posted by Prakash_Radha on 25 Feb 2004 at 7:37 AM
hi, now i'm able to run my code on both windows as well as solaris..... but the only problem is the first line of the script where u specify the perl library has to be changed manually.....

ex: suppose the perl directory is in D: in windows u have to specify
#!D:\\perl
where as in unix if its in the usr/bin/ directory then u have to specify
#!/usr/bin/perl

Is there anyway to overcome this?

Thanks,
prakash.
Report
Re: Writing common script for windows and unix..... Posted by Jonathan on 25 Feb 2004 at 7:49 AM
: hi, now i'm able to run my code on both windows as well as
: solaris..... but the only problem is the first line of the script
: where u specify the perl library has to be changed manually.....
:
: ex: suppose the perl directory is in D: in windows u have to specify
: #!D:\\perl
: where as in unix if its in the usr/bin/ directory then u have to specify
: #!/usr/bin/perl
:
: Is there anyway to overcome this?
:
#! lines are generally only relevant to UNIX systems - Windows as an OS doesn't make use of them to decide what interpreter to use. So there's a good chance you can get away with leaving it as #!/usr/bin/perl. Of course, if Perl isn't there on a UNIX system you're in for some fun. There's always the assume it's in the system path trick and just put #!perl though I don't really recommend this idea (if it was a really good one, everyone would just do it).

I guess in some situations you'll just have to change it!

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.