Solved

Gwting info from a file and using that info

Posted on 2000-05-11
8
127 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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