in reply to using s///g;
You can open the file for both read and write, but that can be tricky. Better to create a new file and rename to old file name.
use strict; use warnings; use File::Copy; my $infilename = 'Pull-2015-08-15-23.txt'; my $outfilename = 'new.file'; my $find = '20150518'; my $replace = '18 May 2015'; open $infile,'<',$infilename; open $outfile,'>',$outfilename; while (my $line = <$infile>) { $line =~ s/$find/$replace/; print $outfile $line; } close $infile; close $outfile; move($outfilename,$infilename);
You may find modules like Date::Parse and Date::Format useful to deal with dates in general, and not just this specific example.
Update:
use Date::Parse; use Date::Format; @time = strptime("20150518"); print strftime("%e %b %Y",@time);
|
|---|