Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Gwting info from a file and using that info

Posted on 2000-05-11
8
128 Views
Last Modified: 2010-03-05
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
Comment
Question by:CODER
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2801096
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
 

Author Comment

by:CODER
ID: 2801193
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
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801252
try using
 
@lines = <CONF>;


instead of

@lines<CONF>



and use

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

instead of
   

if ($db=~ /^DATABASE$/){
   
0
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.

 
LVL 16

Accepted Solution

by:
maneshr earned 25 total points
ID: 2801304
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
 

Author Comment

by:CODER
ID: 2801401
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
 

Author Comment

by:CODER
ID: 2801405
thanks maneshr...
0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801413
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
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801425
oops sorry Maneshr and you are right ..

Im wrong ...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question