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

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

Replies are listed 'Best First'.
Re^5: How to call particular parameter from another configuration file in perl
by hippo (Archbishop) on Jun 11, 2021 at 10:39 UTC
    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.


    🦛

Re^5: How to call particular parameter from another configuration file in perl
by afoken (Chancellor) on Jun 11, 2021 at 10:41 UTC

    <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.
        I created the following structure of files and directories:

        ./CA.pl

        #!/usr/bin/perl use warnings; use strict; use Config::Simple; my $confdir = $ENV{CFG_DIR}; my $conffile = 'LED.cfg'; my $pillar = 'dev'; my $led_cfg = "$confdir/$conffile"; 'Config::Simple'->import_from($led_cfg, \ my %Config); my $ap_id = $Config{ $pillar . '_lcd.AppID' }; print "$ap_id";

        ./cfg/LED.cfg

        [dev_lcd] AppID=APTC_RDFG User=AB12345 [tst_lcd] AppID=APTC_RERF User=AB45678 [pro_lcd] AppID=APTC_RDHF User=AB98765

        ./main.pl

        #!/usr/bin/perl use warnings; use strict; my $pwd = qx{./CA.pl}; print "$pwd\n";

        Now, when I run

        CFG_DIR=./cfg ./main.pl

        I'm getting the expected output:

        APTC_RDFG

        How is your scenario different?

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]