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

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

    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 script. i read parameters from LED configuration file and execute the script to retrieve the password from cyberark server. below are the detailed steps i am trying to achieve.

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

      I get below output when i execute the mainscript
      [1:22 PM] Prakash S Can't call method "param" on an undefined value at /ontw/etc/lcd/ 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);
      <> has param declared as below
      my AppID = $LED.cfg->param( $pillar . "_lcd.AppID); my User = $LED.cfg->param( $pillar . "_lcd.User);
      Once i execute 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 Am i doing something wrong while declaring variable ? do i have to declare "param" somewhere in my mainscript
        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.


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


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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133762]
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
Find Nodes?
    Voting Booth?

    No recent polls found