Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Convert Shell script to Perl

by cdarke (Prior)
on Oct 10, 2011 at 14:41 UTC ( #930652=note: print w/ replies, xml ) Need Help??


in reply to Re: Convert Shell script to Perl
in thread Convert Shell script to Perl

exec does not behave in the same way on Windows and UNIX, so it might be better to use system instead, which is similar on both (although there are still a few differences).

Although the latest ksh93 versions exec on the last statement within a script, I don't think that bash does.

One other thing to be aware of, environment variables on UNIX are case sensitive but on Windows are not - that can catch you out.


Comment on Re^2: Convert Shell script to Perl
Re^3: Convert Shell script to Perl
by akrrs7 (Acolyte) on Oct 10, 2011 at 15:26 UTC
    This is the code:
    use strict; use warnings; $ENV {'LIBDIR'}='$MY_XALANHOME/bin'; $ENV {'LOCALCLASSPATH'}='$ENV{LIBDIR}:/xalan.jar'; $ENV {'LOCALCLASSPATH'}='$ENV{LOCALCLASSPATH}:$ENV{LIBDIR}/xml-apis.ja +r'; $ENV {'LOCALCLASSPATH'}='$ENV{LOCALCLASSPATH}:$ENV{LIBDIR}/xercesImpl. +jar';
    When I run the perl program from the command line using - perl abc.pl - I don't get any error messages. When I run the following command from the commandline:
    perl $ENV{'LIBDIR'}='C:\SOMEFOLDER';
    I get a message saying - can't open perl script "$ENV": no such file or directory. I would've expected to create a new environment variable called LIBDIR with the c:\somefolder as the value ? Thanks
      Two things, you need to tell the Perl interpreter to execute the code rather than look for a file of that name and the environment variables will not be set int the parent process (your shell) only in the Perl process and its children.

      So while perl -e "$ENV{LIBDIR'}='C:\SOMEFOLDER';" would create the varable, it would cease to exist when Perl exited.

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-11-28 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls