[16842] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4254 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 8 00:05:29 2000

Date: Thu, 7 Sep 2000 21:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968385912-v9-i4254@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 7 Sep 2000     Volume: 9 Number: 4254

Today's topics:
    Re: Algorithm for data recognition (Logan Shaw)
    Re: Algorithm for data recognition <awrobinson@home.com>
    Re: Background process <DTOakey@cinci.rr.com>
    Re: Background process (Abigail)
    Re: Background process (Logan Shaw)
    Re: CGI & hashes (Logan Shaw)
    Re: CGI & hashes <jeff@vpservices.com>
        CGI.pm, taint & use strict?? <pdmos23@geocities.com>
    Re: ftp and chmod program (David Efflandt)
    Re: golf: remove .txt from filenames (Ilya Zakharevich)
    Re: Help needed - regexp (Martien Verbruggen)
    Re: how to  encrypt source code? (David H. Adler)
        Last day of month <srhi@home.com>
    Re: Last day of month <stephenk@cc.gatech.edu>
    Re: Last day of month (Craig Berry)
    Re: Last day of month (Logan Shaw)
        perl + Postgres Question <troyr@vicnet.net.au>
    Re: perl + Postgres Question <christopher_j@uswest.net>
    Re: perl book? (David Wall)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 7 Sep 2000 20:20:17 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Algorithm for data recognition
Message-Id: <8p9esh$da3$1@provolone.cs.utexas.edu>

In article <8p97jd$s7n$1@nnrp1.deja.com>,  <awrobinson@my-deja.com> wrote:
>I've got data coming in through email. I need to do two things with it.
>First, I need to account for multi-part mime messages and figure out
>which mime part contains the data. Second, I need to determine if
>records have been wrapped and unwrap them. I've build a regular
>expression that represents a single data record. With the regular
>expression, I can do either 1. or 2. I just haven't figured out how to
>do both at the same time. Could some kind soul point me to an algorithm,
>reference, or idea that would get me over this hump?

Having done pretty much *exactly* this same thing last month, I'll just
tell you the answer.

Go get MIME-tools from CPAN.

Then, use the MIME::Parser::parse (I think) method to create yourself
a MIME::Entity from the mail message.

Then recursively traverse the MIME message -- if it $entity->parts
lists sub-parts, then visit them; otherwise, it's the base case.

I believe dump_entity is a function that comes with MIME-tools that
could serve as an example of a recursive entity traverser.

If you need to return the result, pass a reference variable into your
recursive procedure, and then when you find what you're looking for,
modify the thing referred to by that reference.  I believe you could
use a closure instead, but I don't think it makes anything less
sloppy.  (Because, although you can get to the *data* that you need to
modify easily, you don't know what procedure to call recursively
without passing it in to the anonymous subroutine itself, so it's six
of one and half dozen of the other as far as extra arguments go, but
one uses closures, which some people find confusing.)

As for "wrapped" parts, I guess that means MIME parts that have been
encoded.  If it does, then that part is taken care of for you
automatically when you ask the appropriate MIME module to parse it for
you.

Hope that helps.

  - Logan


------------------------------

Date: Fri, 08 Sep 2000 03:56:36 GMT
From: Andrew Robinson <awrobinson@home.com>
Subject: Re: Algorithm for data recognition
Message-Id: <39B86373.9D87996B@home.com>

Logan Shaw wrote:

> In article <8p97jd$s7n$1@nnrp1.deja.com>,  <awrobinson@my-deja.com> wrote:
> >I've got data coming in through email. I need to do two things with it.
> >First, I need to account for multi-part mime messages and figure out
> >which mime part contains the data. Second, I need to determine if
> >records have been wrapped and unwrap them. I've build a regular
> >expression that represents a single data record. With the regular
> >expression, I can do either 1. or 2. I just haven't figured out how to
> >do both at the same time. Could some kind soul point me to an algorithm,
> >reference, or idea that would get me over this hump?
>
> Having done pretty much *exactly* this same thing last month, I'll just
> tell you the answer.
>
> Go get MIME-tools from CPAN. ...
>
> As for "wrapped" parts, I guess that means MIME parts that have been
> encoded.  If it does, then that part is taken care of for you
> automatically when you ask the appropriate MIME module to parse it for
> you.

Logan, I've pretty much done everything you suggested through traversing the
mime parts. At this point, I'm checking the data in each parts returned from
the mime traversal. I'm trying to distinguish between the "real" data and
things like signatures.

As for wrapping, I'm afraid if the content type of the attachment is text,
the records could still get wrapped. Am I worrying about something I don't
need to worry about?

I appreciate your reply. However, my questions start where your suggestions
leave off. Know of any references for that?

Thanks!

Andrew Robinson






------------------------------

Date: Fri, 08 Sep 2000 01:49:58 GMT
From: "Dwight T. Oakey" <DTOakey@cinci.rr.com>
Subject: Re: Background process
Message-Id: <aBXt5.1$P5.594@typhoon.kc.rr.com>

In article <8p6800$ffs$1@muenster.cs.utexas.edu>, logan@cs.utexas.edu (Logan
Shaw) wrote:


>In article <8p4qj8$l3c$1@nnrp1.deja.com>,  <pedjav@my-deja.com> wrote:
>>Hi,
>>Can anybody give me example of starting a few sub's in background and
>>waiting them to finish and after that print result of those sub's.
>>Something like this
>>sub test1 {$t1="test 1 finished";}
>>sub test2 {$t2="test 2 finished";}
>>sub test3 {$t3="test 3 finished";}
>>
>>backgroundprocess (&test1;&test2;&test3);
>>
>>wait;
>>
>>print $t1,$t2,$t3;
>
>You must use fork() to create the child processes, and you probably
>want to use wait() to wait until one of them (all of them if you do it
>in a loop with the right condition) have exited.
>
>However, it's more complex than that.  What you want to do requires
>interprocess communication.  The processes are separate images that
>cannot modify each other, so they must talk to each other in order to
>pass information.  (Actually, the parent has access to the exit code of
>the children through the "$?" variable after you call wait(), but you
>want to pass strings, so that won't suffice.)
>
>The simplest way to do this may be to use pipes -- create a pipe,
>fork(), and then have the child close one side of the pipe and the
>parent close the other side.  The child can then write to the pipe and
>the parent can read it, and you have one-way communication.
>
>Talking to more than one process at a time is trickier -- you have to
>use IO::Select or something like that.
>
>  - Logan

I have a follow-on question, and a (semi-) related question.

First, the follow-on...  I want to perform the same routine on hundreds
of servers.  Can I use pipe and fork() to create separate processes (one for
each
server) and have them execute at the same time?  I don't need the child
processes to talk to each other, just to pass information to the parent.
The parent will then upload the data to a database.  If I didn't word it
correctly, the key I'm reaching for here is for the processes to work
simultaneously (i.e. in parallel.)  Since I loop through the list of servers
one at a time, some of my programs literally take days to finish. :(  If I
could "parallel process", the program would finish in just a few hours! :)

Second, the semi-related question...  My co-worker codes in VB (yes, we're
a Microsoft shop).  He uses a simple, neat piece of code: do work.
(No period in the code.)  What this allows VB to do is free up the processor
to other programs while his code is idle, such as waiting for a network
request.  Does Perl have anything like this?  I've noticed that Perl is
more processor friendly than VB, but I'd still like to free up more CPU
cycles.

Thanks.
    -Dwight


------------------------------

Date: 08 Sep 2000 02:57:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Background process
Message-Id: <slrn8rglbr.vlt.abigail@alexandra.foad.org>

Dwight T. Oakey (DTOakey@cinci.rr.com) wrote on MMDLXV September MCMXCIII
in <URL:news:aBXt5.1$P5.594@typhoon.kc.rr.com>:
!! 
!! First, the follow-on...  I want to perform the same routine on hundreds
!! of servers.  Can I use pipe and fork() to create separate processes (one for
!! each
!! server) and have them execute at the same time?  I don't need the child
!! processes to talk to each other, just to pass information to the parent.
!! The parent will then upload the data to a database.  If I didn't word it
!! correctly, the key I'm reaching for here is for the processes to work
!! simultaneously (i.e. in parallel.)  Since I loop through the list of servers
!! one at a time, some of my programs literally take days to finish. :(  If I
!! could "parallel process", the program would finish in just a few hours! :)

Perhaps. If you only have one processor, no "parallel processing"
is really happening. However, if you have lots of blocking I/O, then
you might experience a speed up. You could of course use a select loop
as well. But yes, you can use fork()s in Perl and uses pipes too. See
perlopentut.

!! Second, the semi-related question...  My co-worker codes in VB (yes, we're
!! a Microsoft shop).  He uses a simple, neat piece of code: do work.
!! (No period in the code.)  What this allows VB to do is free up the processor
!! to other programs while his code is idle, such as waiting for a network
!! request.  Does Perl have anything like this?  I've noticed that Perl is
!! more processor friendly than VB, but I'd still like to free up more CPU
!! cycles.

No, Perl doesn't have something like this. Perl has its roots in Unix.
In Unix, the OS takes care of that - if some process does a blocking read,
no timeslots will be allocated to it while there's nothing to read.

I guess it shouldn't surprise me, but I'm amazed that Microsoft produces
OSses where each process has to tell the OS it's now time for another process
to do something. What happens if you run a program that does a blocking
read, but doesn't let other processes play with the CPU?



Abigail
-- 
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
          for (s;s;s;s;s;s;s;s;s;s;s;s)
              {s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'


------------------------------

Date: 7 Sep 2000 21:58:11 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Background process
Message-Id: <8p9kk3$do5$1@provolone.cs.utexas.edu>

In article <aBXt5.1$P5.594@typhoon.kc.rr.com>,
Dwight T. Oakey <DTOakey@cinci.rr.com> wrote:
>First, the follow-on...  I want to perform the same routine on hundreds
>of servers.  Can I use pipe and fork() to create separate processes (one for
>each
>server) and have them execute at the same time?

You can do that with just fork().  The pipe() is so that those
processes can send results back to the parent process.  (There are
other methods besides pipe(), by the way.)

Note that each process created by fork() will have a separate process
image, and this will use lots of memory.  So, hundreds of processes
will probably use hundreds of megabytes of memory.

> I don't need the child
>processes to talk to each other, just to pass information to the parent.

That's why I suggested you open a pipe in the parent right before you
fork(); then, each child has a pipe it can use to talk to the parent.

>The parent will then upload the data to a database.  If I didn't word it
>correctly, the key I'm reaching for here is for the processes to work
>simultaneously (i.e. in parallel.)  Since I loop through the list of servers
>one at a time, some of my programs literally take days to finish. :(  If I
>could "parallel process", the program would finish in just a few hours! :)

The way I'd solve this problem is I'd fork() a bunch of child processes
off and have each one do whatever it does, then open a connection to
the database and insert the data, then exit.  That way, you don't have
to pass the data back to the parent process to have it insert it into
the database.  Yes, this results in more database connections, but if
it takes days to run this process, it probably won't be too many
database connections per second.

Another thing I'd do is set up a tunable number of child processes.  If
you have 1000 tasks to do, you probably don't want to start 1000
processes because you probably won't gain anything more than you would
if you start 50 (or more or less, depending on how CPU-bound they are),
and you'll just use more memory.

When I do this kind of thing, it usually looks like this:

	$max_children = 25;

	@tasks = get_list_of_tasks;

	%child_tasks = ();

	while (scalar @tasks or scalar keys %child_tasks)
		{
		# figure out whether we need to start
		# children or wait on them to finish
		if (scalar keys %child_tasks < $max_children)
			{
			# we need more children, so start one
			$task = shift @tasks;

			if ($pid = fork)
				{
				# we are the parent
				if (not defined $pid)
					{
					warn "Uhoh, fork() failed ($!)!\n";
					sleep 30;
					next;
					}

				$child_tasks{$pid} = $task;
				}
			else
				{
				# we are the child
				process_task ($task);
				}
			}
		else
			{
			# we have enough children, so wait for
			# one of them to finish.

			$pid = wait;

			$rc = $? >> 8;

			if ($pid == -1)
				{
				# this shouldn't happen, really.
				warn "Uhoh, wait() returned -1!\n";
				next;
				}

			if ($rc > 0)
				{
				# child process failed -- requeue work.
				push (@tasks, $child_tasks{$pid});
				}
			}
		}

That's not perfect, since if there's a failure on a task it will never
stop retrying until it succeeds, but it's the general idea.

>Second, the semi-related question...  My co-worker codes in VB (yes, we're
>a Microsoft shop).  He uses a simple, neat piece of code: do work.
>(No period in the code.)  What this allows VB to do is free up the processor
>to other programs while his code is idle, such as waiting for a network
>request.

This sounds like cooperative (user space) threading or something.  I'm
not really sure what it is, but I'm pretty sure that Perl doesn't
support it.

By the way, if you are using Perl on Windows, then I believe fork() is
unimplemented, although I could be wrong.

  - Logan


------------------------------

Date: 7 Sep 2000 20:24:10 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: CGI & hashes
Message-Id: <8p9f3q$db6$1@provolone.cs.utexas.edu>

In article <8p9bdp$6n2@news.or.intel.com>,
Kelley Kent <kelley.a.kent@intel.com> wrote:
>Here's my situation: I do a lot data collection with system calls in a CGI
>script,
>display some info and then a series of forms get displayed to the user. But
>I only
>want to collect the data with system calls once, at their initial load of
>the page,
>and then use that information in the series of forms.
>
>So is there an easy way to carry over the data? I tried (in vain) to add
>some elements
>to %ENV, as I thought it was persistant thru CGI scripts.

Since you can't maintain state across CGI scripts at all, usually the
solution is to store everything in a database (using perl's DBI
interface) and create one hidden field (or use part of the URL) that
contains some sort of session key (preferably something random or hard
to guess).  Then, if they give a session key to your CGI, query the
database and get back the information you need.

Also, have a cron job or similar that scans the database for sessions
with really old timestamps and deletes them.

  - Logan


------------------------------

Date: Thu, 07 Sep 2000 18:33:32 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: CGI & hashes
Message-Id: <39B841EC.D1AA867@vpservices.com>

Kelley Kent wrote:
> 
> What would be the best way of sending (or more appropriately "maintaining")
> a hash
> array between CGI scripts. And without making a bunch of hidden variable
> types.

One might ask why you want to avoid "making a bunch of hidden variable
types", but I'll refrain and offer one way to do it:  Turn the hash into
a delimited string and make a single hidden variable that holds it, or
(ugh,yuck,patooie) write the string to a cookie.

For example, if your hash keys and values don't contain equal signs or
semi-colons you could do this:

Create a string from the original hash data (do this only once when the
user enters your form for the first time):

    my $hash_str = '';
    while (my($k,$v)=each %org_hash) {
       $hash_str .= "$k=$v;";
    }
    ...
    print hidden({-name=>'hash',-value=>$hash_str});

On additional usages of the same form, just let CGI.pm's stickiness
carry the hash over:

   print hidden({-name=>'hash'});

When you want to access the hash values, just use split and your
delimiters to re-create the hash from the string in the one hidden
parameter:

    my %hash_from_form = ();
    my @pairs = split ';',param('hash');
    for (@pairs) {
        my($k,$v)=split '=';
        $hash_from_form{$k}=$v;
    }

HTH,

-- 
Jeff


------------------------------

Date: Fri, 08 Sep 2000 02:45:42 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: CGI.pm, taint & use strict??
Message-Id: <39B85345.2CC4CF4@geocities.com>

Snippet of code:

#!/usr/bin/perl -T

use strict;
use CGI qw(:standard);

my $to = "address\@home.com";
my $from = "whomever\@home.com";
my $subject = "Comments";
my $firstname = param("firstname");
my $lastname = param("lastname");
my $comments = param("comments");
my $nextpage = "http://www.nextpage.com/thanks.htm";

open(MAIL, "|/usr/sbin/sendmail -t") || &Error;
flock(MAIL, 2);
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";

print MAIL "Firstname: $firstname\n";
print MAIL "Lastname: $lastname\n\n";
print MAIL "Comments: $comments\n";
flock(MAIL, 8);
close(MAIL);

print "Content-type: text/html\n";
print "Location: $nextpage\n\n";

sub Error {
print "Content-type: text/html\n\n";
print "Can't open sendmail.";
exit;
}
1;

Written this way, it will not work, but if I replace the "-T" with "-w"
on the shebang line, it works fine.  I don't understand what perl sees
is "tainted"?
1. Can "CGI.pm", "taint", & "use strict" be used together as above?
2. Can I use both "-w" & "-T" on the shebang line?
3. Can I use the %formdata parsing script(ie: require "formParse.pl";)
with "use strict" & "-T" to parse the form information instead of using
CGI.pm? When I was using this, I had the taint check working fine, but
when I introduced "use strict" I had problems.

Any suggestions on what to do or what to read would be much appreciated.
I have been searching and reading, reading and searching, but I haven't
found information to answer these questions.
Thanks
Pasquale



------------------------------

Date: Fri, 8 Sep 2000 01:39:26 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: ftp and chmod program
Message-Id: <slrn8rggq9.9f5.efflandt@efflandt.xnet.com>

On Thu, 07 Sep 2000, tobiwan@my-deja.com <tobiwan@my-deja.com> wrote:
> I'd like to write a perl program (not a cgi script) that will
>automatically ftp some files to a remote machine, and change the
>permissions on them _on the remote machine_.
>
>I know how to ftp a file, and I know how to use chmod on a file on my
>local machine - but not how to change permissions via ftp.

Typically SITE is used to run commands that the ftp server supports.  Read
about 'site (ARGS)' in perldoc Net::FTP.  Example (but should really test
for success):

$ftp->site{"chmod 755 $file");

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



------------------------------

Date: 8 Sep 2000 01:58:06 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: golf: remove .txt from filenames
Message-Id: <8p9h3e$mh8$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Matthew Stoker 
<matt.stoker@motorola.com>],
who wrote in article <39B6886C.763D12A@motorola.com>:
> Since windows has so generously appended .txt to all of my text data
> files, I now need to strip the .txt from the filenames of all the files
> in a given directory. After much trial and tribulation (mostly due to
> omitting the chomp), I finally got this to work:
> 
> perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
> `ls`'

  pfind . s/.txt//

But this would look in subdirectories as well.  Use


  pfind -nosubdir . s/.txt//

if this is not desirable.  Use

  pfind . -f s/.txt//

if you do not want renaming directories ;-).

Ilya


------------------------------

Date: Fri, 08 Sep 2000 01:23:52 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Help needed - regexp
Message-Id: <slrn8rgfsp.2cp.mgjv@verbruggen.comdyn.com.au>

On Thu, 07 Sep 2000 09:24:34 GMT,
	Daniel Chetlin <daniel@chetlin.com> wrote:
> On Thu, 7 Sep 2000 19:51:42 +1100,
>  Martien Verbruggen <mgjv@tradingpost.com.au> wrote:

[snip of my previous nonsense]

> Oops, nope -- you're not checking whether the match succeeds or not. Try
> it in reverse:

Arehmm.. yes, right... hmmm... how silly of me.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


------------------------------

Date: 8 Sep 2000 03:40:42 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: how to  encrypt source code?
Message-Id: <slrn8rgntq.kbt.dha@panix6.panix.com>

On Thu, 7 Sep 2000 22:53:16 +0800, DT <dsa@dassda.com> wrote:
>Thank for your ideas and suggestions. You people are nice!

Can we quote you on that?  :-)

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Your question doesn't make any sense. You might as well ask whether
it is possible to grow vegetables from a painting, without becoming
Wednesday first.       - Abigail, c.l.p.misc


------------------------------

Date: Fri, 08 Sep 2000 01:56:50 GMT
From: "Me" <srhi@home.com>
Subject: Last day of month
Message-Id: <CHXt5.15138$AW2.194877@news1.rdc2.pa.home.com>

I wrote a Perl script (under Unix) that works well. Now, I
would like it to do some special end of month reporting on
the last day of each month. The trouble is that I can't seem to
figure out how to use localtime to determine if "today" is the
last day of the month. A search through the date modules on
CPAN didn't prove enlightening. If anyone has a solution to
this problem, please post it on this newsgroup or let me know.

Thanks.




------------------------------

Date: Thu, 07 Sep 2000 22:46:20 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Last day of month
Message-Id: <39B852FC.6F69BCC8@cc.gatech.edu>

Me wrote:

> I wrote a Perl script (under Unix) that works well. Now, I
> would like it to do some special end of month reporting on
> the last day of each month. The trouble is that I can't seem to
> figure out how to use localtime to determine if "today" is the
> last day of the month. A search through the date modules on
> CPAN didn't prove enlightening. If anyone has a solution to
> this problem, please post it on this newsgroup or let me know.
>
> Thanks.

Just check if tomorrow is the first of the month:

if ((localtime(time()+60*60*24))[3] == 1) {
  # end of month stuff
}

perldoc -f localtime

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




------------------------------

Date: Fri, 08 Sep 2000 02:59:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Last day of month
Message-Id: <srglfor1ljn140@corp.supernews.com>

Me (srhi@home.com) wrote:
: I wrote a Perl script (under Unix) that works well. Now, I
: would like it to do some special end of month reporting on
: the last day of each month. The trouble is that I can't seem to
: figure out how to use localtime to determine if "today" is the
: last day of the month. A search through the date modules on
: CPAN didn't prove enlightening. If anyone has a solution to
: this problem, please post it on this newsgroup or let me know.


#!/usr/bin/perl -w
# lastday -- function which determines if a given time value is on the
#   last day of its month (with test harness code).
# Craig Berry (20000907)

use strict;
use Time::Local;


sub isLastDayOfMonth
{
  my $t = shift;
  my @fields = localtime($t);
  $fields[3]++;
  $t = timelocal(@fields);
  (localtime($t))[3] == 1;
}

sub boolStr
{
  (scalar shift) ? 'true' : 'false';
}

print 'Today:   ', boolStr(isLastDayOfMonth(time)), "\n",
      '1/31/00: ', boolStr(isLastDayOfMonth(timelocal(0,0,0,31,0,100))), "\n",
      '2/28/00: ', boolStr(isLastDayOfMonth(timelocal(0,0,0,28,1,100))), "\n",
      '2/29/00: ', boolStr(isLastDayOfMonth(timelocal(0,0,0,29,1,100))), "\n";


-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


------------------------------

Date: 7 Sep 2000 22:18:17 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Last day of month
Message-Id: <8p9lpp$drn$1@provolone.cs.utexas.edu>

In article <39B852FC.6F69BCC8@cc.gatech.edu>,
Stephen Kloder  <stephenk@cc.gatech.edu> wrote:
>Me wrote:
>
>> the last day of each month. The trouble is that I can't seem to
>> figure out how to use localtime to determine if "today" is the
>> last day of the month. A search through the date modules on
>> CPAN didn't prove enlightening.

Date::Calc should be able to do this -- just use it to add one day to
the current date, then check if the month is the same as it was before
you added one.

>Just check if tomorrow is the first of the month:
>
>if ((localtime(time()+60*60*24))[3] == 1) {
>  # end of month stuff
>}

If you want to be anal-retentive and consider the fact that not
all days are 24 hours long, then you have to do something else.

The easiest thing to do is to use Date::Calc, but you can do it
manually if you don't want to install (and compile at runtime) that
module just for this purpose.  Here's some untested example code:

	sub is_last_day
		{
		my ($month, $day, $year) = @_;

		my ($days_this_month);

		$days_this_month = 31 if $month =~ /^(1|3|5|7|8|10|12)$/;
		$days_this_month = 30 if $month =~ /^(4|6|9|11)$/;

		if ($month == 2)
			{
			if ( $year % 400 == 0
				or ($year % 4 == 0 and $year % 100 != 0) )
				{ $days_this_month = 29; }
			else
				{ $days_this_month = 28; }
			}

		return $days_this_month == $day;
		}

You'd want to call that with standard human being days and years and
stuff, meaning don't use any of the weird stuff like "years since
1900".

  - Logan


------------------------------

Date: Fri, 8 Sep 2000 14:37:24 +1100
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: perl + Postgres Question
Message-Id: <E9Zt5.11535$cr3.328406@ozemail.com.au>


Hi Guys..this is more of a sql question than anything else but i'm hopeing
someone can help me answer this

Somehow in my Postgres database I have dulplicate records...ie having the
same primary key..I'm guessing something went wrong when i restored from a
backup

Does anyone know a safe way of removing the duplicates?

ie i can't say delete from tablename where id=26 if there are 2 records
which have the id of 26

Thanks in Advance





------------------------------

Date: Thu, 7 Sep 2000 20:56:09 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: perl + Postgres Question
Message-Id: <xrZt5.1134$M06.309430@news.uswest.net>


"Troy Rasiah" <troyr@vicnet.net.au> wrote:
>
> Hi Guys..this is more of a sql question than anything else but i'm hopeing
> someone can help me answer this
>
> Somehow in my Postgres database I have dulplicate records...ie having the
> same primary key..I'm guessing something went wrong when i restored from a
> backup
>
> Does anyone know a safe way of removing the duplicates?
>
> ie i can't say delete from tablename where id=26 if there are 2 records
> which have the id of 26

That sounds like a nasty problem.  I'm not an expert in this area,
but what I would try to do is save the record data, delete the
record(s), and then re-insert.  If you have identical records down
to the primary key I would imagine that from an SQL point of view
there's no way to distinguish between the records.




------------------------------

Date: 7 Sep 2000 23:23:13 -0400
From: darkon@one.net (David Wall)
Subject: Re: perl book?
Message-Id: <8FA8E757Adarkononenet@206.112.192.118>

ddorward@hotmail.com (David Dorward) wrote in
<39B7ED62.DE2134FF@hotmail.com>: 

>kevin wrote:
>> 
>> so what's THE perl book to buy?
>
>I like the Perl CD Bookshelf

Yeah, except that after I bought it (maybe before), the 3rd edition of the 
Camel came out...  oh well, it's still useful.  Saves me from having to 
type in the recipes from the Cookbook.

-- 
David Wall
darkon@one.net


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4254
**************************************


home help back first fref pref prev next nref lref last post