Brian wrote:
Hi

Hello,

ARGV0 will = AB7Z001
ARGV1 will = AB7Z002
ARGV2 will = 01/01/1900

I would like to read a file, locate AB7Z001 (but not AB7Z0011,  so a space at 
position 8 in string )
Upon location of value in argv0 replace it with argv1.
Then, at the first instance of a date replace it with argv2.
Then, at the next instance of a date, replace it with "today's date".
There will only be one instance of AB7Z001 in the file, but/so, is there a way to stop 
checking and go on to output after this "one event"

So that,

AB7Z001 blahblahblah 01/01/1485 moreblahblah evenmoreblahblah 01/01/1999
AB7Z0011 blahblahblah 01/01/1485 moreblahblah evenmoreblahblah 01/01/1999

will be

AB7Z001 blahblahblah 01/01/1900 moreblahblah evenmoreblahblah 22/10/2008
AB7Z0011 blahblahblah 01/01/1485 moreblahblah evenmoreblahblah 01/01/1999

open (IN, "+<dummy.txt");
@file = <IN>;
seek IN,0,0;
foreach $file (@file){
$file =~ s/............................./g; <----------- ??

print IN $file;
}
close IN;

#!/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 ) = ( '', '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