True. Changing a variable in memory will not change a file. Except when using Tie::File which should be perfect for you.

Normally, to change something in a file, you need to read the file, do your change, and write the file back out.

use strict; use warnings; use POSIX qw( strftime ); use Text::CSV qw( ); use Tie::File qw( ); use constant INHOUSE =>"Open House Information"; { my $today = strftime('%Y/%m/%d', localtime()); tie(my @db, 'Tie::File', 'dbase1.exm') or die("Unable to open database: $!\n"); my $csv = Text::CSV->new(); foreach my $line (@db) { $csv->parse($line) or die("Unable to parse \"$line\"\n"); my @fields = $csv->fields(); my ($status, $date) = $fields[22, 23]; # Convert date to sortable format. my ($m, $d, $y) = split(/\//, $date); $date = "20$y/$m/$d"; my $kill = ($date < $today); # Are you sure this isn't backward +s? if ($status eq INHOUSE && $kill) { $status = ''; } # Reassemble the line and updated the file. $fields[22] = $status; $csv->combine(@fields) or die("Unable to recreate line from fields @fields\n"); # Changing $line causes the file to be updated. $line = $csv->string(); } untie @db; }

If you're trying to remove the entire line, it's even easier:

use strict; use warnings; use POSIX qw( strftime ); use Text::CSV qw( ); use Tie::File qw( ); use constant INHOUSE =>"Open House Information"; { my $today = strftime('%Y/%m/%d', localtime()); tie(my @db, 'Tie::File', 'dbase1.exm') or die("Unable to open database: $!\n"); my $csv = Text::CSV->new(); @db = grep { $csv->parse($line) or die("Unable to parse \"$line\"\n"); my @fields = $csv->fields(); my ($status, $date) = $fields[22, 23]; # Convert date to sortable format. my ($m, $d, $y) = split(/\//, $date); $date = "20$y/$m/$d"; $status ne INHOUSE || $date >= $today } @db; untie @db; }

In reply to Re^3: replace in lines by ikegami
in thread replace in lines by pglinx

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.