Your question is unclear.
But your desire to add two new columns after the first without writing a new file needs more thought.
Your language suggests you think there's some way to change the content of a file (on disk, in RAM) without writing it out to storage again. Sure, you could overwrite the existing file (for some types of changes) but doing so would destroy the original file (and under most OSen write the new version would be written in a different spot on the disk or at a different set of addresses in RAM, anyway). So take advantage of Perl's capabilities (and no, I don't mean the "edit in place" operation, which merely disguises the fact that you are writing a new file).
One standard technique is to write the revised material to a temp file, and, when complete, renamethe original to original.bak (or delete the original) and rename the temp file to the original name. Alternately, write the revised material to a file with a name that indicates its status.
Leaving the actual code for file opening, reading, writing as an exercise, the options above lead to how the question of how to do the insert_processing : Here's one (iterative for clarity) possibility.
#!/usr/bin/perl
use strict;
use warnings;
use 5.012;
my @array = qw (a c e);
for my $item(@array) {
say $item;
}
say "-" x 10;
my $save = $array[1];
my $insert = "b";
splice @array,1,1, ($insert, $save);
for my $item(@array) {
say $item;
}
say "-" x 10;
$save = $array[3];
$insert = "d";
splice @array,3,1, ($insert, $save);
for my $item(@array) {
say $item;
}
All that said, if what it is you plan to insert and the meaning of "Age to FullName" have any real bearing on your problem, you need to clarify your SOPW. |