G'day PilotinControl,

As your files are very small, you could just make working copies where usage is flagged. Each time you find the temp file has been deleted, just recreate the working copies from the master files.

Here's a proof-of-concept script.

#!/usr/bin/env perl use strict; use warnings; use autodie; use File::Copy; use Tie::File; my $master_ext = '.master'; my $used_ext = '.used'; my $year_file_base = 'pm_year_make_model_file_years'; my $make_file_base = 'pm_year_make_model_file_makes'; my $model_file_base = 'pm_year_make_model_file_models'; my $temp_file = 'pm_year_make_model_temp_file'; my $used_years = "$year_file_base$used_ext"; my $used_makes = "$make_file_base$used_ext"; my $used_models = "$model_file_base$used_ext"; if (! -e $temp_file) { copy("$year_file_base$master_ext", $used_years); copy("$make_file_base$master_ext", $used_makes); copy("$model_file_base$master_ext", $used_models); } tie my @years, 'Tie::File', $used_years; tie my @makes, 'Tie::File', $used_makes; tie my @models, 'Tie::File', $used_models; my $year = select_item('year', \@years); my $make = select_item('make', \@makes); my $model = select_item('model', \@models); untie @years; untie @makes; untie @models; open my $fh, '>>', $temp_file; print $fh "$year $make $model\n"; close $fh; print "Temp file contents:\n"; system cat => $temp_file; sub select_item { my ($item, $records_ref) = @_; my %item_index_for = map { $records_ref->[$_] => $_ } grep { $records_ref->[$_] !~ /^#/ } 0 .. $#$records_ref; print "Available ${item}s:\n"; print "$_\n" for sort keys %item_index_for; print "Select $item: "; chomp(my $selection = <STDIN>); substr($records_ref->[$item_index_for{$selection}], 0, 0) = '#'; return $selection; }

Here's some sample runs:

-- Ken


In reply to Re: Flat File Comment by kcott
in thread Flat File Comment by PilotinControl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.