note
pfaut
<p>I would recommend reading the file in once. Then updating the array by inserting each new entry in it's proper place with [splice]. When finished inserting all the new entries, write the file out once.</p>
<code>
my @reg_addrs = qw(bob@domain1.com bob@domain2.com);
open FH,"<",$datafile or die "Could not read virtual file";
my @virtual = <FH>;
close FH;
for my $reg_addr (@reg_addrs) {
my ($name,$domain) = split /@/,$reg_addr;
my ($i) = 0;
for my $entry (@virtual) {
++$i;
if ($entry =~ /\Q$domain\E/) {
splice @virtual,$i,0,"$reg_addr\t$user\n";
last;
}
}
}
open FH,">",$datafile or die "Could not write virtual file";
print FH @virtual;
close FH;
</code>
<center><table><tr><td><font size="-1">90% of every Perl application is already written. [id://246498|⇒]</font></td></tr><tr><td align="right"><font size="-1"><i>[dragonchild]</i></font></td></tr></table></center>
255496
255496