Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by Anonymous Monk
on Jun 11, 2021 at 05:59 UTC ( #11133762=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^3: How to call particular parameter from another configuration file in perl
by choroba (Archbishop) on Jun 11, 2021 at 08:33 UTC
    > 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
        my AppID = $LED.cfg->param( $pillar . "_lcd.AppID); my User = $LED.cfg->param( $pillar . "_lcd.User);

        I don't know what that is but it certainly isn't valid Perl.


        🦛

        <CA.pl> has param declared as below

        my AppID = $LED.cfg->param( $pillar . "_lcd.AppID); my User = $LED.cfg->param( $pillar . "_lcd.User);

        That does not even look remotely like valid perl.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2021-07-23 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?