Brian wrote:

Partial success.

The value <search for> is normally located starting at the 35th char into the line. I split the line so it was at the beginning of a new line and <replace with> worked.
Unfortunately the dates never changed.
I will sleep on this and attack it again in the morning.

Based on the example you provided I assumed that <search for> was at the beginning of the line. If it isn't then you need to use different anchors for the pattern, for example:

#!/usr/bin/perl
use warnings;
use strict;

@ARGV == 3 or die "usage: $0 <search for> <replace with> <date>\n";
my ( $search, $replace, $date ) = @ARGV;

my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ];
my $today = sprintf '%02d/%02d/%04d', $day, $mon + 1, $year + 1900;

( $^I, @ARGV ) = ( '.bak', 'dummy.txt' );

while ( <> ) {
    if ( ? $search ? ) {
        s/(?<= )$search(?= )/$replace/;
        s!\d\d/\d\d/\d{4}!$date!
        and s!($date.*?)\d\d/\d\d/\d{4}!$1$today!;
        }
    print;
    }

__END__




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to