in reply to Inserting lines in a file with Tie::File if lines don't exist
grep can help. It actually helps you in both replace and search (before you do insert). Read perlfunc for details.
use warnings; use strict; my @a = ("a=1", "b=2", "c=3"); for my $e (grep /^b=/, @a) { $e = "b=22"; } print join(",", @a);
The other way is to use hash, as you are handling key-value pairs.
Update:
See my reply to devgoddess's reply. I made a general purpose sub there.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Inserting lines in a file with Tie::File if lines don't exist
by devgoddess (Acolyte) on Dec 31, 2003 at 01:33 UTC | |
by pg (Canon) on Dec 31, 2003 at 01:47 UTC | |
by devgoddess (Acolyte) on Dec 31, 2003 at 01:54 UTC | |
by bean (Monk) on Dec 31, 2003 at 20:34 UTC |