• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

Gwting info from a file and using that info

here is how my config file looks like:
==========================
#Config info
#
#
DATABASE,NODE,file1,user1,passwd1
DATABASE,NODE,file2,user2,passwd2
#
#
===========================
HERE IS WHAT I WANT TO DO:

(1). OPEN THE CONFIG (ITS IN THE DIRECTORY: A/B/CONFIG/configfile)
(2). parse the each line that begis with DATABASE
(3). get all the file(S), user(s) and passwd(s)

(4). Then I need to connect to the files cause they are databases..
       i know how to do that already all i need is the parsing of the file to get
      the desired info.

THANKS ALOT.
CODER
0
CODER
Asked:
CODER
  • 3
  • 3
  • 2
1 Solution
 
maneshrCommented:
try this.
i does what you want.

=================coder.pl
#!/usr/local/bin/perl

open(CONF,"/A/B/CONFIG/configfile") || die $!;
@lines<CONF>;  ## Read all the lines in the file
close(CONF);

foreach $line (@lines){
  next if $line=~ /^#/; ##  Ignore comment lines
  chomp($line); ##  Remove the \n
  ($db,$node,$file,$user,$pass)=split(/,/,$line);
  if ($db=~ /^DATABASE$/){
    print $user," & ",$pass,"\n";
    ## Add your connect code here!!
  }
}
0
 
CODERAuthor Commented:
it does not work
this is what i get:
=====================
35 sciris!PERL> perl test.pl
syntax error at test.pl line 4, near "CONF>"
Execution of test.pl aborted due to compilation errors.      
================================

whats the problem
will this retrieve all the info that I want
0
 
christopher sagayamCommented:
try using
 
@lines = <CONF>;


instead of

@lines<CONF>



and use

if ($db=~ /^DATABASE/){

instead of
   

if ($db=~ /^DATABASE$/){
   
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
maneshrCommented:
the error is cause of the line..
@lines<CONF>;  ## Read all the lines in the file

it should be...
@lines=<CONF>;  ## Read all the lines in the file

Sorry :-0
0
 
CODERAuthor Commented:
why chris??? shoul I use =~/^DATA/ as opposed to putting a $ at the end of DATABASE???
what's the diff?   I thouhgt $ means end of string?
0
 
CODERAuthor Commented:
thanks maneshr...
0
 
christopher sagayamCommented:
2). parse the each line that begis with DATABASE



You wanted the above isnt it ?

Only at the BEGINNING there must be a match ..isnt it ?
0
 
christopher sagayamCommented:
oops sorry Maneshr and you are right ..

Im wrong ...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now