How can I parse this configuration file format (allowing comments) in Perl?
Posted
by rockyurock
on Stack Overflow
See other posts from Stack Overflow
or by rockyurock
Published on 2010-04-04T09:54:56Z
Indexed on
2010/04/04
12:23 UTC
Read the original article
Hit count: 407
perl
I am reading some parameters (from user input) from a .txt file and want to make sure that my script could read it even a space or tab is left before that particular parameter by user.
Also if I want to add a comment for each parameter followed by # , after the parameter (e.g 7870 # this is default port number) to let the user know about the parameter
How can I achieve it in same file?
Right now, I am using split /\|\s/.
Code:
$data_file="config.txt";
open(RAK, $data_file)|| die("Could not open file!");
@raw_data=<RAK>;
@Ftp_Server =split(/\|\s/,$raw_data[32]);
config.txt (user input file)
PING_TTL | 1 CLIENT_PORT | 7870 FTP_SERVER | 192.162.522.222
Could any body suggest me a robust way to do it?
/rocky
© Stack Overflow or respective owner