in reply to insert label into file

Your request concerning the date/time stamp is not clear to me. I have guessed that you wish to replace the current date/time stamp with a new one showing the current date/time. Apologies if that is incorrect, please clarify what you are trying to do. Anyway, here is my guess:
use strict; use warnings; use POSIX qw(strftime); # Open the file for read and write open (my $fh, '+<', 'data.dat') or die "Unable to open data.dat: $!"; # Specified: day/month/yyyy h:m:s am or pm # assumed dd/mm/yyyy hh:mm:ss am/pm my $new_stamp = strftime ('%d/%m/%Y %I:%M:%S %p',localtime); # This gets AM/PM insteam of am/pm, so: $new_stamp =~ s/([PA]M)$/lc $1/e; while (<$fh>) { # Replace date/time stamp with new one if (s|\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d [ap]m|$new_stamp|) { seek ($fh,-length($_)-1, 1); print $fh $_; } } close ($fh)

Replies are listed 'Best First'.
Re^2: insert label into file
by grashoper (Monk) on Mar 23, 2009 at 19:42 UTC
    All I really want to do with the date/time is echo it back into my sql db as a date/time value, I also want to push a label into the hash so that it becomes date->timevalue, does this make sense? it seems my sql insert is thinking the date is a string.