in reply to Re^4: How to call particular parameter from another configuration file in perl
in thread How to call particular parameter from another configuration file in 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". ;-)
  • Comment on Re^5: How to call particular parameter from another configuration file in perl
  • Download Code

Replies are listed 'Best First'.
Re^6: How to call particular parameter from another configuration file in perl
by Prakee (Initiate) on Jun 11, 2021 at 11:53 UTC
    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]
        Thanks for your response. Now i able to narrow down the issue. I am getting desired output if i execute the script under /amex/lcd directory. If i copy the script to /amex/log/ directory and execute the script, i am getting below error.
        $pwd /amex/lcd $./CA.pl <password> ## printing password as expected $cd /amex/log $./CA.pl ## not printing the password from different location other + than /amex/lcd 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);
        Am i missing something that you can help me with ? If i sort out this issue of getting the password executed from all directory other than /amex/lcd, then i will able to get main.pl executed without issue. Thanks in advance.