Compare UNIX file time with time in a variable

P

phynkel

Application: web

Background: The web page gets a string from the user and it's passed to
PERL. PERL runs a UNIX find command to find files with that string.
Then there's a lot of processing before the results are returned to the
user.

Problem: The user wants a web page option that will allow them to set
the "latest" possible date of the files that can be searched.

My idea: Get date string from user input. Use that string in a PERL
system command to "touch" a file with that date. Something like

system 'touch --date $lastdate /tmp/touchfile';

Then the PERL system command running the find will look for files
older than "/tmp/touchfile".

I'm looking for a simpler and/or cleaner way to do things. Any
thoughts?

I don't want to make more than one pass of the files, so I want to get
everything I can out of the find command as it does some other inline
processing before getting back to PERL

TX
 
M

Mumia W. (reading news)

Application: web

Background: The web page gets a string from the user and it's passed to
PERL. PERL runs a UNIX find command to find files with that string.
Then there's a lot of processing before the results are returned to the
user.

Problem: The user wants a web page option that will allow them to set
the "latest" possible date of the files that can be searched.

My idea: Get date string from user input. Use that string in a PERL
system command to "touch" a file with that date. Something like

system 'touch --date $lastdate /tmp/touchfile';

Then the PERL system command running the find will look for files
older than "/tmp/touchfile".

I'm looking for a simpler and/or cleaner way to do things. Any
thoughts?

I don't want to make more than one pass of the files, so I want to get
everything I can out of the find command as it does some other inline
processing before getting back to PERL

TX

What have you tried so far?

First, do validity checking on $lastdate before giving it to the system
command, or you'll be sorry.

Second, I'd advise using File::Find and checking against the $lastdate
before pushing the files onto an array (in the wanted function).
 
P

phynkel

Mumia said:
What have you tried so far?

First, do validity checking on $lastdate before giving it to the system
command, or you'll be sorry.

of course, but thanks
Second, I'd advise using File::Find and checking against the $lastdate
before pushing the files onto an array (in the wanted function).

2n d time this advice was mentioned - must be good -will lokk it up
after having coffee :) tx!
 
P

phynkel

Sherm said:
The name of the language is Perl, not PERL.


Have a look at File::Find. Much easier to use from within a Perl script,
and allows you to write a callback function that can use whatever criteria
you want to filter out files you're not interested in.

sherm--

TX - will look it up .

This little project was my intro to Perl. Originally was used in its
simplest form, now is becoming more complex and is being used by a
bunch of researchers every day.

tx for the advice.
 
B

Big and Blue

TX - will look it up .

And if you still decide to use command line find, use GNU find, which
has -amin, -cmin, -mmin options which allows you to find files accessed,
(inode-)changed or modified before (+n), after (-n) or exactly at (n) n
minutes ago.
 
P

phynkel

That's neat. Will Red Hat Linux, by default use GNU find? Now if only
GNU find would sort the output by file date. I can do that in PERL so
it's no biggy
My hack (touching a file and comparing time stamps) works fine.



TX
 
P

phynkel

That's neat. Will Red Hat Linux, by default use GNU find? Now if only
GNU find would sort the output by file date. I can do that in PERL so
it's no biggy
My hack (touching a file and comparing time stamps) works fine.



TX
 
P

phynkel

That's neat. Will Red Hat Linux, by default use GNU find? Now if only
GNU find would sort the output by file date. I can do that in PERL so
it's no biggy
My hack (touching a file and comparing time stamps) works fine.



TX
 
M

Martijn Lievaart

[ Please don't toppost ]

That's neat. Will Red Hat Linux, by default use GNU find? Now if only

Yes, it is called GNULinux, becuase it's the Linux kernel with the GNU
tools. This holds for any distro I know of.

M4
 
M

Martijn Lievaart

Yes, it is called GNULinux, becuase it's the Linux kernel with the GNU
tools. This holds for any distro I know of.

s.GNULINUX.GNU/Linux.;
s.becuase.because.;

Damn.

M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top