Read a configuration file: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Fix Perl 6 -> Raku in comments) |
m (remove duplicated entry) |
||
Line 2,142: | Line 2,142: | ||
Note that <tt>seedsremoved</tt> doesn't exist. |
Note that <tt>seedsremoved</tt> doesn't exist. |
||
=={{header|J}}== |
=={{header|J}}== |
||
<lang j>require'regex' |
|||
set=:4 :'(x)=:y' |
|||
cfgString=:4 :0 |
|||
y set '' |
|||
(1;&,~'(?i:',y,')\s*(.*)') y&set rxapply x |
|||
) |
|||
cfgBoolean=:4 :0 |
|||
y set 0 |
|||
(1;&,~'(?i:',y,')\s*(.*)') y&set rxapply x |
|||
if.-.0-:y do.y set 1 end. |
|||
) |
|||
taskCfg=:3 :0 |
|||
cfg=: ('[#;].*';'') rxrplc 1!:1<y |
|||
cfg cfgString 'fullname' |
|||
cfg cfgString 'favouritefruit' |
|||
cfg cfgBoolean 'needspeeling' |
|||
cfg cfgBoolean 'seedsremoved' |
|||
i.0 0 |
|||
)</lang> |
|||
Example use: |
|||
<lang j> taskCfg 'fruit.conf' |
|||
(,' = ',]&.do)&>;: 'fullname favouritefruit needspeeling seedsremoved' |
|||
fullname = Foo Barber |
|||
favouritefruit = banana |
|||
needspeeling = 1 |
|||
seedsremoved = 0 </lang> =={{header|J}}== |
|||
<lang j>require'regex' |
<lang j>require'regex' |