Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: insert label into file

by cdarke (Prior)
on Mar 20, 2009 at 16:05 UTC ( #752093=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://752093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-05-24 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?