Solved

Gwting info from a file and using that info

Posted on 2000-05-11
8
126 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now