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

> 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]

Replies are listed 'Best First'.
Re^4: How to call particular parameter from another configuration file in perl
by Prakee (Initiate) on Jun 11, 2021 at 10:25 UTC
    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". ;-)
        Thanks you both for responding.

        I will explain the usage of configuration file from CA.pl.

        CA.pl is calling LED.cfg configuration file to check the server name. If it is Development server, CA.pl will look for dev_lcd in LED.cfg config file and use App.ID & User to connect to cyberark server. _lcd is just a notation used to connect to respective server development, test, production.
        LED.cfg dev_lcd AppID=APTC_RDFG User=AB12345 tst_lcd AppID=APTC_RERF User=AB45678 pro_lcd AppID=APTC_RDHF User=AB98765
        my AppID = $LED.cfg->param( $pillar . "_lcd.AppID); AppID=AppID configured in cyberark LED.cfg = configuration file where all server AppID and user names are + stored param = calling the AppID from LED.cfg using _lcd syntax and assign to + $AppID pillar = searches the server if belongs to development or test or prod +uction. if $pillar is development, dev_lcd is connected and AppID und +er dev_lcd is assigned to $AppID.
        If there is any other way to assign the variable from LED.cfg to $AppID and $user, please let me know. I can follow the same. I am very new to perl and using this method by taking reference from very old existing script.

        Once CA.pl fetches the correct AppID and User based on pillar(dev/tst/prod servers), it will connect to cyberark and provides the password. I am getting the password successfully if i run the script manually. But output of this CA.pl is used to connect to database of another perl main script. I tried many methods to retrieve the password but i failed with undef error as mentioned.

        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 someone help me on this.