Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by choroba (Cardinal)
on Jun 11, 2021 at 12:16 UTC ( [id://11133783]=note: print w/replies, xml ) Need Help??


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

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]

Replies are listed 'Best First'.
Re^8: How to call particular parameter from another configuration file in perl
by Prakee (Initiate) on Jun 17, 2021 at 08:00 UTC
    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.

      The path you give to Config::Simple is relative to the current directory. It is not relative to where your script sits.

      If you want to use a config file from a given directory, you need to specify that directory explicitly in the name of the config file, like:

      my $config = Config::Simple->new("/path/to/config.ini");

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found