$ cat test.conf fieldX:fieldY=123 fieldA:fieldB=234 $ cat t.pl #!/usr/bin/perl use warnings; use strict; { package MyConfig; use Tie::File; sub new { my ($class, $file) = @_; tie(my @config, "Tie::File", $file) or die("Failed to read ", $file, "\n ", $!); return bless \@config, $class; } sub setting { my $self = shift; my $line = shift; if (3 == grep { defined($_) } @_) { $self->[$line] = "$_[0]:$_[1]=$_[2]"; } else { return split /[:=]/, $self->[$line]; } } sub DESTROY { untie @{ $_[0] } } } use Data::Dumper; my $s = MyConfig->new("test.conf"); my @set1 = $s->setting(0); # at line 1 my @set2 = $s->setting(1); # at line 2 print Dumper \@set1, \@set2; $s->setting(1, "foo", "bar", "777"); # modify line 2 $s->setting(4, "baz", "red", "999"); # add line 5 __END__ $ t.pl $VAR1 = [ 'fieldX', 'fieldY', '123' ]; $VAR2 = [ 'fieldA', 'fieldB', '234' ]; $ cat test.conf fieldX:fieldY=123 foo:bar=777 baz:red=999

In reply to Re: Config file changes by repellent
in thread Config file changes by aartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.