Delete/Archive older enteries.

2003-11-06 Thread Sara
I am trying to modify an already existing piece of code. This piece of
code -> opens a db file -> split the records (one of which is date when the
record was added) -> compare the dates with current date -> and remove all
the records if those are old enteries (as specified to remove e.g 7 days old
enteries). So the database gets updated automatically and all the old
enteries are deleted.

Now what I am trying to do is to append deleted enteries to another file
too. In case, If I need to access older enteries I can access that archived
file.

Any ideas?

Thanks for you help.

Sara.


# DB FILE #

John|06-Nov-2003
Doe|05-Nov-2003
Smith|04-Nov-2003
Sara|03-Oct-2003
Deiley|02-Oct-2003

#

#!/usr/bin/perl

use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';

use CGI;

my $q = new CGI;


my $db_file_name = 'test.txt';

my $remove = 3; # Number of days old.

my $today = &date_to_delete(&get_delete_date);

my $removeby = $today - ($remove * 86400);

open (READ, "$db_file_name") || die "unable to open DB FILE $!";

my @lines = ;

close (READ);

print $q->header();


open (DB, ">$db_file_name") || die "can't open the file again $!";

foreach my $line(@lines) {
chomp $line;
my ($name, $id);
($name, $id) = split (/\|/, $line);
if ($removeby > &date_to_delete($id)){next;}
print DB "$line\n";
}
close DB;

print "Data Updated - Old Enteries Deleted!";


sub get_delete_date {
# 
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the
&date_to_unix
# subroutine below which converts your date format into a unix time in
seconds for sorting
# purposes.

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) =
localtime(time());
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}

sub date_to_delete {
# 
# This routine must take your date format and return the time a la UNIX
time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4,
"Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

##

P.S. The above two sub-routines are taken from: DBMan -
http://www.gossamer-threads.com/

#



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



HTTP::Request

2003-11-06 Thread Tobias Fink
Hi,

why doesn't

my $ua = LWP::UserAgent->new;   
my $res = $ua->request(GET 'http://www.google.de/search', q  => 'asdasd');
if ($res->is_success) {
 my  $server_response = $res->content;
 print $server_response;
}

print the html-source of http://www.google.de/search?q=asdasd ?


Regards,

Tobias

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: HTTP::Request

2003-11-06 Thread Wiggins d'Anconia
Tobias Fink wrote:
Hi,

why doesn't

my $ua = LWP::UserAgent->new;   
my $res = $ua->request(GET 'http://www.google.de/search', q  => 'asdasd');
if ($res->is_success) {
 my  $server_response = $res->content;
 print $server_response;
}

print the html-source of http://www.google.de/search?q=asdasd ?

It has a syntax error.  Or is this not your real code?  Among other 
problems.

perldoc LWP::UserAgent

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Simple CGI question

2003-11-06 Thread Jack
Hello,

I'm trying to redirect the output of my CGI (written
in Perl) to another frame,
but I'm not exactly sure how to do this.  i.e. I have
two frames on my page
one on the right and one on the left.  There is a form
on the right frame.  When
the user clicks on the Submit button on my form, I'd
like to call a CGI script and
redirect its output to the left frame.  Could anyone
please tell me how I can do this?

Any help would be greatly appreciated.

Thanks,

 Jack

__ 
Post your free ad now! http://personals.yahoo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: HTTP::Request

2003-11-06 Thread Sara
#!/usr/bin/perl
use CGI;
use LWP::UserAgent;

my $q = new CGI;

my $query = $q->param('query') || 'LWP';

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

my $response = $ua->get("http://search.cpan.org/search?query=$query";);

if ($response->is_success) {

my $server_response = $response->content;

print $server_response;

}





- Original Message -
From: "Tobias Fink" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, November 07, 2003 4:12 AM
Subject: HTTP::Request


> Hi,
>
> why doesn't
>
> my $ua = LWP::UserAgent->new;
> my $res = $ua->request(GET 'http://www.google.de/search', q  => 'asdasd');
> if ($res->is_success) {
>  my  $server_response = $res->content;
>  print $server_response;
> }
>
> print the html-source of http://www.google.de/search?q=asdasd ?
>
>
> Regards,
>
> Tobias
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



removing apache

2003-11-06 Thread BetaGamma
Hi guys...
 
If I want to remove my apache server do I need to only delete the $HOME/apache 
directory and delete the enteris from my .cshrc or anything else is also required.
 
Thanks
 
Pawan



-
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Re: Simple CGI question

2003-11-06 Thread Andrew Gaffney
Jack wrote:
Hello,

I'm trying to redirect the output of my CGI (written
in Perl) to another frame,
but I'm not exactly sure how to do this.  i.e. I have
two frames on my page
one on the right and one on the left.  There is a form
on the right frame.  When
the user clicks on the Submit button on my form, I'd
like to call a CGI script and
redirect its output to the left frame.  Could anyone
please tell me how I can do this?
In the right frame, put this:

...


substituting 'leftframe' for the name of the left frame and 'yourscriptlocation.pl' for 
the URL of your script.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: HTTP::Request

2003-11-06 Thread drieux
On Thursday, Nov 6, 2003, at 15:12 US/Pacific, Tobias Fink wrote:
[..]
why doesn't

my $ua = LWP::UserAgent->new;
my $res = $ua->request(GET 'http://www.google.de/search', q  => 
'asdasd');
if ($res->is_success) {
 my  $server_response = $res->content;
 print $server_response;
}

print the html-source of http://www.google.de/search?q=asdasd ?
well there seems to be a series of issues, not the
least of which is that when I try the simple command
line routine with the lwp-request code I get a 'forbidden'
response back from www.google.com - so even IF I can put
the string
	http://www.google.com/search?q=asdasd

into a browser, the simple request
[jeeves: 13:] lwp-request 'http://www.google.com/search?q=asdasd'

An Error Occurred

An Error Occurred
403 Forbidden


[jeeves: 14:]
suggest that they may have 'issues' with web-bots. which you
would notice with say code like:
my $res = $ua->get('http://www.google.com/search?q=asdasd');
if ($res->is_success) {
 my  $server_response = $res->content;
 print $server_response;
} else {
print "request failed\n";
print $res->content ;
}
At which point let us go back and look at the problem
with your line
	my $res = $ua->request(GET 'http://www.google.de/search', q  => 
'asdasd');

sorry, but that just does NOT make sense to me. I can see what you were
trying to do, but that is way garbled.
IF you know what your query should be, then why not append it to
the base 'uri' that you have
if you will go back to

	perldoc LWP::UserAgent

you will note that the more classical form, if you do not
want to do the 'get()' method is to construct the HTTP::Request object,
( cf HTTP::Request ) and pass that object:
 $request = HTTP::Request->new('GET', 'http://search.cpan.org/');
  # and then one of these:
 $response = $ua->request($request);
so yes, the line is broken, but there also seems to be an interesting
server side issue that google has with web-bots.
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Delete/Archive older enteries.

2003-11-06 Thread drieux
On Wednesday, Nov 5, 2003, at 23:12 US/Pacific, Sara wrote:
[..]
foreach my $line(@lines) {
chomp $line;
my ($name, $id);
($name, $id) = split (/\|/, $line);
if ($removeby > &date_to_delete($id)){next;}
print DB "$line\n";
}
close DB;
[..]

that's the operable part of your problem,
it is in this foreach loop that the decision is made
whether code is "deletable" - hence
if ( $removeby > &date_to_delete($id))
{
print SAVEDB "$line\n";
next;
}
and just make sure that you did the appropriate open()
for that file handle, etc...
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Simple CGI question

2003-11-06 Thread drieux
On Thursday, Nov 6, 2003, at 16:42 US/Pacific, Andrew Gaffney wrote:
Jack wrote:
[..]
  When
the user clicks on the Submit button on my form, I'd
like to call a CGI script and
redirect its output to the left frame.  Could anyone
please tell me how I can do this?
In the right frame, put this:

...


substituting 'leftframe' for the name of the left frame and 
'yourscriptlocation.pl' for the URL of your script.
neet solution there, I hadn't thought about arming the 'onClick'.

but why not have the form line simple sort it out for him?

eg:

	
	
	

my assumption is that the 'frames' were set up with something like:

 

   
  

 
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: removing apache

2003-11-06 Thread Wiggins d'Anconia
BetaGamma wrote:
Hi guys...
 
If I want to remove my apache server do I need to only delete the $HOME/apache directory and delete the enteris from my .cshrc or anything else is also required.
 
This is a Perl list, there are many lists for apache questions.  There 
are way to many possiblities to entertain before answering this 
question, not the least of which what OS are you on, how did you install 
the software, yada yada yada.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Simple CGI question

2003-11-06 Thread Andrew Gaffney
drieux wrote:
On Thursday, Nov 6, 2003, at 16:42 US/Pacific, Andrew Gaffney wrote:

Jack wrote:
[..]

  When
the user clicks on the Submit button on my form, I'd
like to call a CGI script and
redirect its output to the left frame.  Could anyone
please tell me how I can do this?


In the right frame, put this:

...


substituting 'leftframe' for the name of the left frame and 
'yourscriptlocation.pl' for the URL of your script.


neet solution there, I hadn't thought about arming the 'onClick'.

but why not have the form line simple sort it out for him?

eg:




I would have suggested this over my previous solution if I had known you could use the 
TARGET attribute in a FORM tag.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Simple CGI question

2003-11-06 Thread drieux
On Thursday, Nov 6, 2003, at 18:10 US/Pacific, Andrew Gaffney wrote:
[..]
...


substituting 'leftframe' for the name of the left frame and 
'yourscriptlocation.pl' for the URL of your script.
neet solution there, I hadn't thought about arming the 'onClick'.
but why not have the form line simple sort it out for him?
eg:



I would have suggested this over my previous solution if I had known 
you could use the TARGET attribute in a FORM tag.

--
Andrew Gaffney
if it's any help you might want to pick up the
O'Reily "Dynamic HTML: The Definitive Reference",
since I have found it IMPERATIVE. There is stuff
that is allowed in one DOM but not another, of
the three of them.
cf:

for my default listing of books one might as well just
break down and put on the shelf.
I found the O'Reilly Book a life saver as it lists
what the canonical alleged attributes are, and which
of them are known only to which group. I actually
had to pull it out to check my foggy memory before
responding...


ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]