Home: Perl Programming Help: Beginner:
Perl script does not work after migrating from AIX to Linux



wlinliang
New User

Jul 18, 2013, 2:19 PM


Views: 2356
Perl script does not work after migrating from AIX to Linux

hi,



after migration perl from aix to Linux, the script does not work.

here is the code and error message:#!/usr/bin/kshexport SCRIPT=$(basename $0)export PROJECT_DIR=/usr/local/aml3/opfIN_FILE=/usr/local/aml3/opf/OCIF/cfg/eval_config.cfgcat $IN_FILE | \
perl -ne \
'
sub leave { print STDERR $ENV{SCRIPT}, ": file [", $ENV{IN_FILE}, "]: line [$lineCount]: error: [", $_[0], "]", "\n";
exit 1
} $line = $_;
$line =~ s/\n//o;
$out = ""; $lineCount++; while ($line =~ m/ (([^\$] | \$[0-9])+) | (( \$ ( ({ [_a-zA-Z][_a-zA-Z0-9]* } ) |
( [_a-zA-Z][_a-zA-Z0-9]* )
)
)+)
/xgo)
{
if ($1) { $out .= $1 }
if ($3) { open E, "eval print -n \"$3\" |" or leave "cannot eval";
read E, $e, 4096 or leave "cannot read from eval";
close E;
$out .= $e
} # the open above fails if eval returns an error
# or if eval does not output anything to stdout
} printf $out, "\n";
'--------sh: print: command not found
test_perl.ksh: file []: line [1]: error: [cannot read from eval]
the sample test file: /usr/local/aml3/opf/OCIF/cfg>cat eval_config.cfg
${PROJECT_DIR}/OCIF/cfg/catalog.cfg.templ : ${PROJECT_DIR}/OCIF/cfg/catalog.cfg
${PROJECT_DIR}/OCIF/cfg/all_tables.dat.templ : ${PROJECT_DIR}/OCIF/cfg/all_tables.dat




thanks.--------


FishMonger
Veteran / Moderator

Jul 18, 2013, 4:05 PM


Views: 2353
Re: [wlinliang] Perl script does not work after migrating from AIX to Linux

Your error message is not coming from perl, it's coming from the shell script code.


FishMonger
Veteran / Moderator

Jul 18, 2013, 4:20 PM


Views: 2351
Re: [wlinliang] Perl script does not work after migrating from AIX to Linux

The first problem I see is at the beginning, starting with the shebang line.

Code
#!/usr/bin/kshexport

You're missing the space between ksh and export.

Are you actually running all of those shell statements as a single line without a space separating some of the statements?


wlinliang
New User

Jul 18, 2013, 4:44 PM


Views: 2349
Re: [FishMonger] Perl script does not work after migrating from AIX to Linux

that is copy/paste issue to lose space.



after I change

if ($3) { open E, "eval print -n \"$3\" |" or leave "cannot eval";

to



if ($3) { open E, "eval echo -n \"$3\" |" or leave "cannot eval";



it works now. thanks.