Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

File manipulation

by rootkidd (Initiate)
on Mar 09, 2001 at 21:34 UTC ( #63279=perlquestion: print w/replies, xml ) Need Help??

rootkidd has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I am currently building a webtool for my work. I have just started to use perl ( which I love) but I am having trouble getting data from one file to another. I have a cgi main page and a script on another page that takes the data and submits it to a database. The trouble is I need to then get the time the second page was submited from the second page onto the first page. I am sure I need to add something like

$date = ""; open (FILE, "< $data") || die "$!"; $timestamp = $time; close (FILE);

I need to get the timestamp from the second page to be appended to a field in the first page. Im not asking for you to tell me how to do it step by step but any information would be great.

Thanx alot :) Ohh, I have only been using perl for 3 weeks or so :(

Replies are listed 'Best First'.
(jeffa) Re: File manipulation
by jeffa (Bishop) on Mar 09, 2001 at 21:55 UTC
    I prefer to store all of my timestamps as epoch seconds. Perl's built-in time returns the number of epoch seconds since January 1, 1970. As long as you have the epoch seconds, you can always figure the rest out. It's a good consistent trick to have.

    For example: pick a date, what was date before that? If you picked Jan 15 then the answer is Jan 14, no matter what year. But what if you picked March 1?

    However, by taking advantage of epoch seconds, you can easily figure out what yesterday was:

    my $yesterday = time - (60 * 60 * 24); my ($d, $m, $y) = (localtime($yesterday))[3,4,5]; $yesterday = sprintf("%04d/%02d/%02d", $y += 1900, $m += 1, $d);


Re: File manipulation
by jeroenes (Priest) on Mar 09, 2001 at 21:59 UTC
    You can get the age of the file with  -M "$path/$file" or with stat. Take a look at localtime, Date::Manip or Date::Calc for info how to handle those difficult date formats.....

    Hope this helps,

    "We are not alone"(FZ)

Re: File manipulation
by Tuna (Friar) on Mar 09, 2001 at 21:42 UTC
Re: File manipulation
by dvergin (Monsignor) on Mar 09, 2001 at 23:49 UTC
    If I follow your original question correctly, you are not asking how to get a timestamp, but rather, how to pass that timestamp (or anything else) from a posting cgi script to a displaying cgi script.

    Let's call them and and map out the transitions: spits out a page with a form in it
    which displays in the user's browser. User responds and according to the form action the data is sent back to
    which processes it and then spits out just an http location: header line specifying's url and includes in the url the needed data (either in the extended path or the query string)
    which goes to the user's browser and quickly bounces back
    to which retreives the needed data using and posts the page accordingly

    The added advantage of the bounce technique is that it prevents the "Repost form data" message if the user hits the reload button.

    If this is what you were looking for, you might find these further details helpful also.

Re: File manipulation
by CiceroLove (Monk) on Mar 09, 2001 at 23:27 UTC
    I actually had to do this not too long ago. Not exactly this but close. I used a command utime which is basically like touch on a UNIX system. But maybe I misunderstood.

    Fates! We will know your pleasures: That we shall die, we know; 'Tis but the time, and drawing days out, that men stand upon. - Act III,I, Julius Caesar

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://63279]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-08-05 21:53 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.