Here's my goal --- open an existing database, add a unique number in order to be able to differentiate each line between the next, read that number so when asked "Would you like to delete this record? (Y/N)", that line can be deleted through a common form INPUT Checkbox and the remaining lines in the database will be pushed up to the top of the database so everything's nice and pretty again. Sounds simple, right? Not for a Perl newbie it's not.
This is an example of what my text database looks like:
Oct 10|Larry|10012|123 Any Street
Oct 15|Moe|85224|5 Main Pl.
Oct 18|Curly|63033|1313 Mockingbird Lane
...etc...
I need to count the number of lines (or records) in the database and then add the new field in front of the date's array so it looks like the following...
0|Oct 10|Larry|10012|123 Any Street
1|Oct 15|Moe|85224|5 Main Pl.
2|Oct 18|Curly|63033|1313 Mockingbird Lane
...etc...
Here's what I tried to do, but it I'm getting Chunk errors...
my $field_cnt1 = "0";
open (DB, "$file") | | die ("Unable to open file $file");
@all = <DB>;
while (@all) {
unshift(@all, "$field_cnt1++");
print DB "$field_cnt1|";
}
close (DB);
}
Maybe there's an easier way to accomplish the same results without having to alter (add) to the existing database?
Also, do I need to use file locking? While one person is deleting their record, that operation won't affect another person wight be adding their record to the same database, at the same time. If so, how?
Thanks!
This is an example of what my text database looks like:
Oct 10|Larry|10012|123 Any Street
Oct 15|Moe|85224|5 Main Pl.
Oct 18|Curly|63033|1313 Mockingbird Lane
...etc...
I need to count the number of lines (or records) in the database and then add the new field in front of the date's array so it looks like the following...
0|Oct 10|Larry|10012|123 Any Street
1|Oct 15|Moe|85224|5 Main Pl.
2|Oct 18|Curly|63033|1313 Mockingbird Lane
...etc...
Here's what I tried to do, but it I'm getting Chunk errors...
Code:
sub add_field { my $field_cnt1 = "0";
open (DB, "$file") | | die ("Unable to open file $file");
@all = <DB>;
while (@all) {
unshift(@all, "$field_cnt1++");
print DB "$field_cnt1|";
}
close (DB);
}
Maybe there's an easier way to accomplish the same results without having to alter (add) to the existing database?
Also, do I need to use file locking? While one person is deleting their record, that operation won't affect another person wight be adding their record to the same database, at the same time. If so, how?
Thanks!