jo5621 has asked for the wisdom of the Perl Monks concerning the following question:

I have two instance on my cfg file that I am already calling, but I want to take the second argument from my string (which is the password) decrypt it, with a variable we use within the organization and then connect into that instances to run a query which get some info, this is the piece of code I have so far and the format of the instances, user/password@instnace:

my %options=(); getopts("c:f:h",\%options); my $instance_file = $options{'f'} if defined ($options{f}); my $CollConnect=$options{'c'} if defined ($options{c}); my $CollTableName = 'CCPM_TABLE_SPACE_COLL'; my $DateOraFmt="'YYYYMMDD HH24:MI:SS'"; if (!open(INSTANCES,"$instance_file")) { Amoc::logit("Unable to open file: $instance_file"); } else { while(my $string_inst = <INSTANCES>){ chomp($string_inst); if($string_inst =~ /(.*)\/(.*)@(.*)/) { do { my $pass = (~/path DEC $2); print "$pass\n"; } } } }

Replies are listed 'Best First'.
Re: Connecting to an instance after spliting it with a regexe
by Anonymous Monk on Jul 28, 2014 at 20:40 UTC

    Your code could use some general touching up, but except for one thing your code seems to work for me - $2 does contain the password after the match.

    The main problem is this bit: "(~/path DEC $2)", which isn't valid Perl - what is that supposed to do? I'm going to wager a guess that you're attempting to call an external command? Then have a look at qx/STRING/ or even better, capture from IPC::System::Simple.

    Your description of what you want to then do is too vague for me to suggest anything. How are the passwords encrypted? What do you mean with "use within the organization"? How do you want to "connect into that instance" - what protocol are we talking about, and do you already have a module or code to do this?

      Thanks for pointing me to the right direction, actually what I wanted to do was your first hint and about how do i encrypt passwords? I do that running the environment variable on the code (a code I didn't write) , connecting into the DB it's next thing I wan to figure out, now that I already get the password through command sqlplus from unix with format "user/pass@instance"

      { my $output = `~/prod/alert/bin/Enc3DesUtils DEC $2`; print "$output\n"; }

        To connect to a database what you'll need is DBI and the appropriate driver, which in your case I'm assuming is DBD::Oracle. There are plenty of tutorials online about DBI, here's something from an O'Reilly book (might be a little dated). It seems to me that in your case DBI is probably the way to go. For more advanced database access and ORM, see DBIx::Class.