in reply to Re: Tie::File question
in thread Tie::File question
I'm certain there is a better way to parse the CSV file but I'm not allowed to add perl modules in our setup.(otherwise I would use a excel parser module) I also had to consider possible string combinations in the values.#Open add_lines.csv and add lines where needed open(ADD, "$addstrings") || die("cannot open file $addstrings"); @addlines=<ADD>; close(ADD); foreach $line (@addlines) { ($section,$newline)=split(/,<>,/,$line); chomp $section; chomp $newline; $newline = "\n".$newline; &AddLine($settings, $section, $newline); } sub AddLine{ my $file = $_[0]; my $section = $_[1]; my $newline = $_[2]; use Tie::File; tie @array, 'Tie::File', $file or die ("cannot open $file"); print "Looking for section: $section so we can add line: $newline\ +n"; foreach (@array){ if (/\Q$section\E/){ $_ .= $newline; last; } } untie @array;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Tie::File question
by ikegami (Patriarch) on Aug 09, 2008 at 01:44 UTC |