Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to read in a config file. 1

Status
Not open for further replies.

nawlej

Programmer
Mar 26, 2004
380
US
Hey everyone. I am tryiong to read in a configuration file into my script. It is using the following format:

[CONFIG1]
texthere
texthere
texthere
[/CONFIG1]

[CONFIG2]
texthere
texthere
texthere
[/CONFIG2]

I am trying to store into an array the values in between these delimiters, but am unsure how. Can anyone give me an idea? Thank you.

-Eric
 
Code:
my @arr;
my $saw_config = 0;
while (<DATA>) {
    chomp;
    if (/\[CONFIG/) {
        $saw_config++;
        next ;
    }
    if (/\[\/CONFIG/) {
        $saw_config--;
        next ;    
    }
    if ($saw_config) [
        push @arr, $_ ;
    }
}
 
Thanks, I figured it out last night though. I did it a little differently because I wanted the brackets to be the new array name, so it wasnt anything I could have added to a defined array, and the names were different for different config files. I appreciate the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top