Solved

How to set env-var in pkg subrtn to be effective in perl script ?

Posted on 2006-07-06
6
322 Views
Last Modified: 2013-11-18
How can I make env-vars set in package suprtns effective on return to perl script ?
I have included testenv1.pl & testexport1.pm below
testenv1.pl calls subrtn exportfile in testexport1.pm to set env-var LOGICALfilename=PhysicalFileName
- this works for Micro Focus COBOL programs with 'external' on the select assign statements
- BUT why does it not work for $symbols referenced in the perl script ?
- I specify 'use Env;' which should make env-vars available to perl script ?
- which works for symbols such as $HOME already set,
- but does not seem to work for $SYMBOLs set in the subrtn
- makes no sense if COBOL can get it (via getenv I assume) why not the perl script ?

#!/usr/bin/perl
# testenv1 - perl script to test 'use Env'
# - why efective only for symbols already in env
# - why NOT for symbols added to env by script ???
use Env; use testexport1;
print("HOME=$HOME\n"); #<-- 'use Env' works for symbols already defined
exportfile("SORTIN","ar/sales.items");  #<-- subrtn adds SORTIN to env
#=====================================
# - exportfile subrtn adds $SYMBOLS to the environment
# - effective for COBOL which gets symbol defs from environment
# cobrun program   <-- my COBOL programs do see $SYMBOLs set in exportfile subrtn
#===========
# - BUT why are these $SYMBOLS not seen by perl script ? (via 'use Env;') ?
print("DEBUG1: SORTIN=$SORTIN\n");  #<-- $SORTIN is still null ?
$SORTIN = $ENV{SORTIN};     #<-- redefine here (already done in subrtn)
print("DEBUG2: SORTIN=$SORTIN\n");  #<-- now we see it
exit(0);
#
#-----------------------------------------------------------------------
# testexport1.pm - perl subrtns to support perl scripts converted from MVS JCL
#                - see doc at: www.uvsoftware.ca/mvs2unix.htm
#                - export files for Micro Focus COBOL
#                - export LOGICAL-filename $SYMBOLS with physical-filenames
#
# profile should include following so perl modules will be found
#   export PERL5LIB=$UV/perlm:$PERL5LIB  # perl modules 'use'd by perl scripts
#   ===================================
#
package testexport1;
use Env; Exporter;
our (@Export, @ISA);
@ISA = qw(Exporter);
@EXPORT = qw(exportfile);
#
# exportfile CUSTMAS ap/customer.master    #<-- JCL/script call
# =====================================
# export CUSTMAS=ap/customer.master        #<-- result
# =================================
#Note - main reason for using this function (vs coding export directly)
#       is to display the DDname & DSNname on the console log
#
sub exportfile
{
$lfd=$_[0]; $lbl=$_[1];        # capture args into named variables
#
if ( "$lfd" && "$lbl" ) { ; }
else { print("exportfile requires 2 args: DDNname=$lfd, DSName=$lbl\n");
       exit(81);
     }
#
$ENV{$lfd} = "$lbl";     # export LogicalName = PhysicalName
#===================     # COBOL programs need LFD in environment
#
# display lfd & lbl with filesize
$fsize = (-s "$RUNDATA/$lbl");
$fmsg = sprintf("file: %s=%s bytes=%d",$lfd,$lbl,$fsize);
print("$fmsg\n");
return(0);
}
0
Comment
Question by:Owen_Townsend
6 Comments
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17054493
looks like you have a syntax error here:

package testexport1;
use Env; Exporter;

should be:

package testexport1;
use Env;
use Exporter;


Also, the Env module is probaly not doing what you think or hope it is.
0
 

Author Comment

by:Owen_Townsend
ID: 17055131
Thanks Perl Diver, but changing to 'use Exporter;' made no difference.
Owen
0
 
LVL 84

Expert Comment

by:ozo
ID: 17056569
$ENV{SORTIN} = "ar/sales.items";
require Env; import Env;
print "$SORTIN\n";
0
 

Author Comment

by:Owen_Townsend
ID: 17059044
Thanks to all above for taking the time to reply.
I should have explained what I am trying to do here.
I am converting mainframe JCL to perl scripts to run on unix/linux.
My objective was to define files for COBOL using just 1 line per file,
since there could be many files prior to each COBOL program execution.
I think now I need 2 lines per file as follows:

1.  exportfile("SORTIN","ar/sales.items");  # subrtn adds SORTIN to env
    #=====================================  # via: $ENV{$_[0]} = "$_[1]";
2a. use Env ("SORTIN");       # suggested by kenslate & anno4 <-- IT WORKS
    #==================
2b. $SORTIN = $ENV{SORTIN};   # OR I could use this (less overhead ?)
    #======================

I think I should probably use '2b.' above as the 2nd line,
since I assume there would be less overhead.
I was converting JCL to Korn shell scripts & am now changing over to perl.
If interested please see www.uvsoftware.ca/mvsjcl.htm
and I will soon have a new doc called mvsjclperl.htm.
Thanks again to all the respondents above.

Owen
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17479002
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to run a side-by-side staging website 16 66
Coova-Chilli can't work with URL using HTTPS! 3 270
website content maintenance 3 100
Grunt Copy file to another destination. 1 56
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question