Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to call particular parameter from another configuration file in perl

by Anonymous Monk
on Jun 04, 2021 at 18:21 UTC ( #11133528=note: print w/replies, xml ) Need Help??


in reply to How to call particular parameter from another configuration file in perl

I think there are two questions you should ask yourself:

  1. Does $ApID contain what you think it does? and
  2. Is the shell script actually receiving the value Perl is trying to send it?

The first is easy enough: insert print "\$ApID='$ApID'\n" before you spawn the command. This assumes $ApID contains all printable characters. If not, you may need to enlist the aid of Data::Dumper, Data::Dump, YAML, JSON, or whatever your favorite dumper/serializer is.

The second is harder, because it may not be obvious what the shell is doing with what you have given it. If you can modify $path/CA.sh, have it echo $ApID and see what you get.

Replies are listed 'Best First'.
Re^2: How to call particular parameter from another configuration file in perl
by Anonymous Monk on Jun 11, 2021 at 05:59 UTC
    Yayyyy. I am not a perl expert and I am in beginner level. But I finally did it after 2 days of struggle. Below is the syntax that i have used and fetching ApId.
    use warnings; use Config::Simple; my $confdir = $ENV{CFG_DIR}; $conffile = 'LED.cfg'; my $LEDcfg = "$confdir/$conffile"; print `cat $LEDcfg\n`; Config::Simple->import_from('LED.cfg', \%Config); $LEDcfg = new Config::Simple('LED.cfg'); $ApID = $LEDcfg->param('ApID'); %Config = $LEDcfg->vars(); print "$ApID\n";

    Now i am able to read the ApID from LED.cfg file. And the next thing is that, i would like to run the perl script and pass the output to another variable $pwd inside main perl script . For ex

    <main Script 1> my $pwd = `($path/CA.pl)`; ## CA.pl is <script 2> chomp ${pwd}; print "$pwd"; ## print the output
    If i run the CA.pl manually, i am able to retrieve the desired password. I am able to connect to database server If i run as below.
    $./$path/CA.pl password1234 $pwd=password1234 mainscript1.pl Connected to Oracle database $
    But i could not capture the output of $path/CA.pl and parse the output to $pwd inside mainscript1. I tried below ones but no luck.
    my $pwd = qx($path/CA.pl); my $pwd = qx("$path/CA.pl"); my $pwd = system($path/CA.pl); my $pwd = system('$path/CA.pl'); my $pwd = system('usr/local/bin/perl -w $path/CA.pl');
    Can you help me run script 2 named $path/CA.pl inside mainscript1 and parse the output to $pwd variable inside main script. I expect the output of $pwd=password1234. Thanks for your guidance as always
      > my $pwd = qx($path/CA.pl);

      This should work. Maybe check $? on the next line, it should be zero if the script executed successfully. system returns an exit code, you can't capture the output with it.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        It did not work. Is it because, i use param inside CA.pl script. i read parameters from LED configuration file and execute the CA.pl script to retrieve the password from cyberark server. below are the detailed steps i am trying to achieve.

        -user id, database name, app.id are present in LED.cfg configuration file. -/ont/lcd/CA.pl connects to cyberark server based on above config file and retrieves the password named as "pwcxxxxxx" -there is another main script called as DB.pm. that is also perl script. -i would like to run this script /ont/lcd/CA.pl and parse output to $pwd. And so i tried using <my $pwd = qx(/ont/lcd/cybeark.pl);> -so that mainscript will use $pwd to connect to database.

        I get below output when i execute the mainscript DB.pm
        [1:22 PM] Prakash S Can't call method "param" on an undefined value at /ontw/etc/lcd/PWCCAauth_succ.pl line 108 (#1) (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an undefined value. Som +ething like this will reproduce the error: $BADREF = undef; process $BADREF 1,2,3; $BADREF->process(1,2,3);
        <CA.pl> has param declared as below
        my AppID = $LED.cfg->param( $pillar . "_lcd.AppID); my User = $LED.cfg->param( $pillar . "_lcd.User);
        Once i execute CA.pl manually, i get the password for the respective AppID, User mentioned in the configuration file LED.cfg. But this is not happening while running from mainscript DB.pm Am i doing something wrong while declaring variable ? do i have to declare "param" somewhere in my mainscript DB.pm

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-08-06 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?