Read a configuration file: Difference between revisions

From Rosetta Code
Content added Content deleted
(wiki formatting)
m (fixed formatting of displayed config file; added buillet points to variable list)
Line 7: Line 7:
# Lines that begin with a hash symbol or semicolon are treated as
# Lines that begin with a hash symbol or semicolon are treated as
# comments and will be ignored
# comments and will be ignored

# This is the fullname parameter
# This is the fullname parameter
FULLNAME Foo Barber
FULLNAME Foo Barber

# This is a favourite fruit
# This is a favourite fruit
FAVOURITEFRUIT banana
FAVOURITEFRUIT banana

# This is a boolean that should be set
# This is a boolean that should be set
NEEDSPEELING
NEEDSPEELING

# This boolean is commented out
# This boolean is commented out
; SEEDSREMOVED
; SEEDSREMOVED
Line 23: Line 23:
For the task we need to set four variables according to the configuration entries as follows:
For the task we need to set four variables according to the configuration entries as follows:


fullname = Foo Barber
*fullname = Foo Barber
favouritefruit = banana
*favouritefruit = banana
needpeeling = true
*needpeeling = true
seedsremoved = false
*seedsremoved = false

Revision as of 22:11, 10 February 2011

Read a configuration file is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The task is to read a configuration file in standard configuration file, and set variables accordingly. For this task, we have a configuration file as follows:

# This is a configuration file in standard configuration file format
#
# Lines that begin with a hash symbol or semicolon are treated as
# comments and will be ignored

# This is the fullname parameter
FULLNAME Foo Barber

# This is a favourite fruit
FAVOURITEFRUIT banana

# This is a boolean that should be set
NEEDSPEELING

# This boolean is commented out
; SEEDSREMOVED


For the task we need to set four variables according to the configuration entries as follows:

  • fullname = Foo Barber
  • favouritefruit = banana
  • needpeeling = true
  • seedsremoved = false