[24642] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6806 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 13:01:30 2004

Date: Tue, 3 Aug 2004 10:00:50 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 3 Aug 2004     Volume: 10 Number: 6806

Today's topics:
        Date::MSAccess V 1.01 <ron@savage.net.au>
        DBI cannot connect to mysql at a specified socket locat <yezq@mail.cbi.pku.edu.cn>
    Re: DBI cannot connect to mysql at a specified socket l <gnari@simnet.is>
        DBIx::Admin::BackupRestore V 1.01 <ron@savage.net.au>
        DBIx::Admin::TableInfo V 1.02 <ron@savage.net.au>
        DBIx::Hash2Table V 2.00 <ron@savage.net.au>
        DBIx::HTML::ClientDB V 1.04 <ron@savage.net.au>
        DBIx::HTML::LinkedMenus V 1.06 <ron@savage.net.au>
        DBIx::HTML::PopupRadio V 1.09 <ron@savage.net.au>
        DBIx::MSAccess::Convert2Db V 1.04 <ron@savage.net.au>
        DBIx::MSSQLReporter V 1.03 <ron@savage.net.au>
        DBIx::Table2Hash V 1.13 <ron@savage.net.au>
        Debugger angst <clint@belle.0lsen.net>
    Re: Debugger angst <dwilga-MUNGE@mtholyoke.edu>
    Re: Debugger angst (Peter Scott)
    Re: Debugger angst <clint@belle.0lsen.net>
    Re: Debugger angst <clint@belle.0lsen.net>
        DFA::Command V 1.98 <ron@savage.net.au>
        Dijkstra and Perl (was Re: Breaking out of nested subro (Greg Bacon)
    Re: Dijkstra and Perl (was Re: Breaking out of nested s <bik.mido@tiscalinet.it>
    Re: Dijkstra and Perl (was Re: Breaking out of nested s <abigail@abigail.nl>
    Re: double eval? (bettyann)
        Efficiency in code to cycle log file <domenico_discepola@quadrachemicals.com>
    Re: Efficiency in code to cycle log file <jgibson@mail.arc.nasa.gov>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
        Example code wanted for talking to Groupwise via IMAP4. (K. L. Estes)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Jul 2004 06:15:36 GMT
From: Ron Savage <ron@savage.net.au>
Subject: Date::MSAccess V 1.01
Message-Id: <I1qH70.1q4C@zorch.sf-bay.org>

The pure Perl module Date::MSAccess V 1.01
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.01  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Mon, 2 Aug 2004 23:55:27 +0800
From: "Zhiqiang Ye" <yezq@mail.cbi.pku.edu.cn>
Subject: DBI cannot connect to mysql at a specified socket location
Message-Id: <celnto$kjs$1@mail.cn99.com>

Dear all,
       I encountered this problem:
When I start the mysql daemon using the default configuration( that is ,
don't use $HOME/.my.cnf file)
then mysql's socket is located at  /tmp/mysql.sock
And, my perl dbi script can work well.

But if I start the mysql daemon using the $HOME/.my.cnf file ( it specifies
the socket location : $HOME/tmp,
port is 2001 not 3306),  mysqld is work at $HOME/tmp/mysql.socket.
At this time, the command line of connecting mysql works OK. (mysql -u
root -p ), it can automatically
find the socket location.
But the perl dbi script doesn't work. It tries to open the socket at
/tmp/mysql.sock, of course , it can
not connect to mysql.

Is there any method to specify the socket's location for perl DBI to find
mysql.sock?
Thank you very much.  The code looks like this:

use strict;
use DBI;

my $database="test";
my $hostname="localhost";
my $cnf_file="/home/somebody/.my.cnf";
my $usr = "root";
my $password = "123456";


my $dsn="DBI:mysql:$database; mysql_socket=/home/somebody/tmp/mysql.sock";
my $dbh=DBI->connect($dsn,$usr,$password) or die "$DBI::errstr";




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

Date: Mon, 2 Aug 2004 20:07:15 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: DBI cannot connect to mysql at a specified socket location
Message-Id: <cem6po$o86$1@news.simnet.is>

"Zhiqiang Ye" <yezq@mail.cbi.pku.edu.cn> wrote in message
news:celnto$kjs$1@mail.cn99.com...
> Dear all,
>        I encountered this problem:
> When I start the mysql daemon using the default configuration( that is ,
> don't use $HOME/.my.cnf file)
> then mysql's socket is located at  /tmp/mysql.sock
> And, my perl dbi script can work well.
>
> But if I start the mysql daemon using the $HOME/.my.cnf file ( it
specifies
> the socket location : $HOME/tmp,

totally uninformed guess:
try /home/somebody/tmp

maybe the .my.cnf file does not expand $HOME

gnari






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

Date: Thu, 29 Jul 2004 06:15:58 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::Admin::BackupRestore V 1.01
Message-Id: <I1qH73.1vrL@zorch.sf-bay.org>

The pure Perl module DBIx::Admin::BackupRestore V 1.01
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.01  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:16:19 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::Admin::TableInfo V 1.02
Message-Id: <I1qH76.3DE@zorch.sf-bay.org>

The pure Perl module DBIx::Admin::TableInfo V 1.02
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.02  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Add comments to the POD about having tested against MySQL V 4, MS Access V 2 (sic) and MS Access 2002
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:16:38 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::Hash2Table V 2.00
Message-Id: <I1qH78.1q51@zorch.sf-bay.org>

The pure Perl module DBIx::Hash2Table V 2.00
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

2.00  Mon Jul 19 14:43:00 2004
	- Change the API, so that the constructor's parameter 'columns' no longer does
		double duty. Now, instead of a single parameter 'columns', you use 2 parameters:
		'columns' and 'extras'. The new parameter 'columns' takes exactly the same 3
		values as did the old parameter of the same name, and any other values, which you
		previously had to put in sorted order at the end of the old parameter 'columns',
		can now be placed in any unsorted order in the new parameter 'extras'. The API
		should have always been like this - the previous design was very confusing.
		Since no new functionality has been introduced in V 2.00, there is no need to
		upgrade, unless compatibility with Module::Build is important (see next point)
	- Change Makefile.PL to coexist with Module::Build
	- Rewrite the docs to help clarify the structure of the hash ref which is saved to
		the database
	- Patch examples/test-hashref2table.pl to match the new API
	- Delete ./test.pl
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:16:53 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::HTML::ClientDB V 1.04
Message-Id: <I1qH7C.1vsC@zorch.sf-bay.org>

The pure Perl module DBIx::HTML::ClientDB V 1.04
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.04  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Delete ./test.pl
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:17:11 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::HTML::LinkedMenus V 1.06
Message-Id: <I1qH7G.3E5@zorch.sf-bay.org>

The pure Perl module DBIx::HTML::LinkedMenus V 1.06
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.06  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Delete ./test.pl
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:17:27 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::HTML::PopupRadio V 1.09
Message-Id: <I1qH7J.1q5s@zorch.sf-bay.org>

The pure Perl module DBIx::HTML::PopupRadio V 1.09
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.09  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Delete ./test.pl
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:17:43 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::MSAccess::Convert2Db V 1.04
Message-Id: <I1qH7L.1vt1@zorch.sf-bay.org>

The pure Perl module DBIx::MSAccess::Convert2Db V 1.04
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.04  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:18:01 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::MSSQLReporter V 1.03
Message-Id: <I1qH7q.3Gs@zorch.sf-bay.org>

The pure Perl module DBIx::MSSQLReporter V 1.03
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.03  Mon Jul 19 14:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Delete ./test.pl
	- Add examples/*.pl. These examples are updated versions of tutorials 12, 14 and 15:
		http://savage.net.au/Perl-tuts-1-30.html
	- Test examples/*.pl against MS SQL Server V 8.
		Warning: I could not get any of the MSDE examples to work with MS SQL Server V 8
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Thu, 29 Jul 2004 06:18:19 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DBIx::Table2Hash V 1.13
Message-Id: <I1qH7u.1vvx@zorch.sf-bay.org>

The pure Perl module DBIx::Table2Hash V 1.13
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.13  Tue Jul 20 20:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Delete ./test.pl
	- Delete 'use Data::Dumper;' from Table2Hash.pm, left over from testing
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Fri, 30 Jul 2004 06:30:49 GMT
From: Clint Olsen <clint@belle.0lsen.net>
Subject: Debugger angst
Message-Id: <slrncgjqop.18d4.clint@belle.0lsen.net>

One of the things I can't stand about Perl is the debugger.  It really
lacks compared to C debuggers, and I can't for the life of me figure out
why this has to be.  Do most Perl programmers just use print to debug their
code?

When I get the runtime error 'Can't use string ("BLAH") as an ARRAY
ref...', the first thing you would expect is that the debugger stop
excution immediately so you can inspect what access caused the problem.
For example, in a multi-level data structure access, how can I tell which
particular access resulted in a violation?

$$hr{abc}[123][456] = $foo; # ????

Instead Perl bails out completely, so while the call stack is nice, that's
all you get!

Secondly, what's with the lack of ability to go up/down frames in the
stack?  You can use 'T' to view the call stack, but in traditional
debuggers, you can view variables etc. at each stack frame to actually find
out /how/ you got into a particular predicament.  So, I end up having to
put on my psychic hat to figure how how I /might/ have gotten there and
hope I can set a sensible breakpoint.

Thanks,

-Clint


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

Date: Fri, 30 Jul 2004 10:21:07 -0400
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: Debugger angst
Message-Id: <dwilga-MUNGE-A25FE4.10210730072004@nap.mtholyoke.edu>

In article <slrncgjqop.18d4.clint@belle.0lsen.net>,
 Clint Olsen <clint@belle.0lsen.net> wrote:

> One of the things I can't stand about Perl is the debugger.  It really
> lacks compared to C debuggers, and I can't for the life of me figure out
> why this has to be.  Do most Perl programmers just use print to debug their
> code?

I agree that perl's debugger is a bit lacking, though not really very 
much compared to gdb (ack, ptooey!).

There are a few graphical perl debuggers and IDEs that probably address 
some of what you want:

http://sourceforge.net/projects/ddd/
http://sourceforge.net/projects/ptkdb/
http://sourceforge.net/projects/open-perl-ide/

However, if you're looking for commandline-only debugging, then I think 
the answer you're going to get from most folks who read this newsgroup 
is: perl's debugger is written in perl, and it's open source. So feel 
free to develop a better one. ;-)

-- 
Dan Wilga          dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **


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

Date: Fri, 30 Jul 2004 15:51:40 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Debugger angst
Message-Id: <g8uOc.144030$ek5.75258@pd7tw2no>

In article <slrncgjqop.18d4.clint@belle.0lsen.net>,
 Clint Olsen <clint@belle.0lsen.net> writes:
>One of the things I can't stand about Perl is the debugger.  It really
>lacks compared to C debuggers, and I can't for the life of me figure out
>why this has to be.  Do most Perl programmers just use print to debug their
>code?

Some of us use the debugger quite a bit.  Some of us have even
written books featuring it :-)

>When I get the runtime error 'Can't use string ("BLAH") as an ARRAY
>ref...', the first thing you would expect is that the debugger stop
>excution immediately so you can inspect what access caused the problem.
>For example, in a multi-level data structure access, how can I tell which
>particular access resulted in a violation?
>
>$$hr{abc}[123][456] = $foo; # ????

Run it under the debugger again and set a breakpoint for that line.
You wouldn't want the overhead of the debugger on every execution,
would you?

>Secondly, what's with the lack of ability to go up/down frames in the
>stack?  You can use 'T' to view the call stack, but in traditional
>debuggers, you can view variables etc. at each stack frame to actually find
>out /how/ you got into a particular predicament.  So, I end up having to
>put on my psychic hat to figure how how I /might/ have gotten there and
>hope I can set a sensible breakpoint.

Which is why I developed the 'y' command which allows you to inspect
lexicals at higher stack frames.  perldoc perldebug.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: Fri, 30 Jul 2004 18:16:06 GMT
From: Clint Olsen <clint@belle.0lsen.net>
Subject: Re: Debugger angst
Message-Id: <slrncgl436.18d4.clint@belle.0lsen.net>

On 2004-07-30, Peter Scott <peter@PSDT.com> wrote:
>>$$hr{abc}[123][456] = $foo; # ????
>
> Run it under the debugger again and set a breakpoint for that line.
> You wouldn't want the overhead of the debugger on every execution,
> would you?

Of course not.  But if I'm running the code in the debugger, I've already
accepted the overhead.  Trap the problem, and allow the user to inspect the
data that's there.  Don't unroll and bail out on me...

The line I showed above only failed under certain conditions.  This happens
in Perl all the time.  So, just setting a breakpoint does nothing.  I could
succeed hundreds of times on this line.  Coming up with the condition can
be really irritating in a situation like this:

$foo = $$hr{abc}[123]{def}[456]; # one level is undef, which one?

So, in a multidimensional hash/array access, just telling me an array or
hash was 'undef' doesn't tell me a whole lot.  Since Perl has runtime type
checking, it would seem that it should be able to tell me /which/ thingy
was malformed.

> Which is why I developed the 'y' command which allows you to inspect
> lexicals at higher stack frames.  perldoc perldebug.

Ok, I'll install PadWalker and see if I can make this thing work for me.

Thanks,

-Clint


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

Date: Fri, 30 Jul 2004 18:22:18 GMT
From: Clint Olsen <clint@belle.0lsen.net>
Subject: Re: Debugger angst
Message-Id: <slrncgl4ep.18d4.clint@belle.0lsen.net>

On 2004-07-30, Dan Wilga <dwilga-MUNGE@mtholyoke.edu> wrote:
>
> I agree that perl's debugger is a bit lacking, though not really very 
> much compared to gdb (ack, ptooey!).

I would sure like to know where you think gdb is lacking in capability.  I
think the end-all of capabilties in gdb is [hardware] watchpoints.  Either
I don't understand how watches workin Perl or they are abysmal.  Every time
an object goes out of scope I get a notice that the value of a particular
object has changed.  This is especially common in scripts not using
file-scoped lexicals.  I've tried dereferencing an object so I could
actually look at the actual object in question, but it doesn't seem to
help.

> http://sourceforge.net/projects/ddd/
> http://sourceforge.net/projects/ptkdb/
> http://sourceforge.net/projects/open-perl-ide/

Thanks for the links.  I'll check them out.  Although my preference would
be for a graphical debugger that actually did not wrap around Perl's
command-line debugger.  The user interface is pretty terse.

Thanks,

-Clint


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

Date: Thu, 29 Jul 2004 06:18:35 GMT
From: Ron Savage <ron@savage.net.au>
Subject: DFA::Command V 1.98
Message-Id: <I1qH7w.1vwM@zorch.sf-bay.org>

The pure Perl module DFA::Command V 1.98
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.98  Tue Jul 20 20:43:00 2004
	- Change Makefile.PL to coexist with Module::Build
	- Add t/pod.t to test all PODs
--
Cheers
Ron Savage, ron@savage.net.au on 29/07/2004
http://savage.net.au/index.html




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

Date: Mon, 02 Aug 2004 12:58:53 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Dijkstra and Perl (was Re: Breaking out of nested subroutine?)
Message-Id: <10gsekdbaqjrpa1@corp.supernews.com>

In article <slrncgoacb.6hs.abigail@alexandra.abigail.nl>,
    Abigail  <abigail@abigail.nl> wrote:

: [...]
: BTW, I've no doubt that Mr. Dijkstra would have the same dim opinion
: about Perl as a language as he had for 'goto' as a statement.

I'm sure you're right, but I'd be interested in seeing more about why
you think so.

Greg
-- 
There is no waste in government . . . The re-election rate of incumbents
proves that the programs are very efficient; they do exactly what they're
designed to do. 
    -- Harry Browne


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

Date: Mon, 02 Aug 2004 23:08:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Dijkstra and Perl (was Re: Breaking out of nested subroutine?)
Message-Id: <l0atg0hp3qg46sb8n7beprngehd4gdgktc@4ax.com>

On Mon, 02 Aug 2004 12:58:53 -0000, gbacon@hiwaay.net (Greg Bacon)
wrote:

>: BTW, I've no doubt that Mr. Dijkstra would have the same dim opinion
>: about Perl as a language as he had for 'goto' as a statement.
>
>I'm sure you're right, but I'd be interested in seeing more about why
>you think so.

Just to name one, have you noticed all those funny predefined,
full-of-side-effects (and "massive" ones too!) variables? ;-)


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: 02 Aug 2004 22:01:12 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Dijkstra and Perl (was Re: Breaking out of nested subroutine?)
Message-Id: <slrncgted8.i4t.abigail@alexandra.abigail.nl>

Greg Bacon (gbacon@hiwaay.net) wrote on MMMCMLXXXIX September MCMXCIII in
<URL:news:10gsekdbaqjrpa1@corp.supernews.com>:
}}  In article <slrncgoacb.6hs.abigail@alexandra.abigail.nl>,
}}      Abigail  <abigail@abigail.nl> wrote:
}}  
}} : [...]
}} : BTW, I've no doubt that Mr. Dijkstra would have the same dim opinion
}} : about Perl as a language as he had for 'goto' as a statement.
}}  
}}  I'm sure you're right, but I'd be interested in seeing more about why
}}  you think so.


That's mostly based on memories when I was still doing research at a
university where a lot of the members of the staff were Dijkstra adepts,
and his (handwritten (!)) notes were faxed, copied and distributed among
staff members, who were supposed to study them as if it was a gospel. I
still think that there was a shrine dedicated to him in the small room
that was always closed.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 25 Jul 2004 16:24:39 -0700
From: bettyann@campbell.com (bettyann)
Subject: Re: double eval?
Message-Id: <287ea6c.0407251524.44a703f3@posting.google.com>

bob + ben,

thanks.  now that i understand *what* we're matching (basically, a
filename that cannot contain [space], et al), i better understand
*how* you did it.

thanks for all your help.  i do appreciate your efforts.
- bettyann


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

Date: Wed, 28 Jul 2004 18:14:19 -0400
From: "Domenico Discepola" <domenico_discepola@quadrachemicals.com>
Subject: Efficiency in code to cycle log file
Message-Id: <UwVNc.39538$vO1.194402@nnrp1.uunet.ca>

Hello.  I wrote a subroutine that creates log file entries in a text file
using the following format: script name version date time status message.  A
sample entry would be:

script v1.0.2 2004/07/12 12:29:18 (I): Message 1 here
script v1.0.2 2004/07/12 12:29:48 (I): Message 2 here
etc.

The important part is that the first 5 "fields" are space seperated whose
positions will not change.  I now wanted to cycle the log file if the date
of the log file entry was greater than a certain value, based on today's
date.  In other words, delete all log file entries older than X days.  The
code I posted works well enough for me but it is not very elegant.  Right
now, the script simply creates a "temporary" file with the log file entries
I want to keep, leaving the original file untouched.  I would consider it a
learning experience if someone can provide me with some suggestions for
tightening the code.

Regards,

Domenico
###############

#!perl
use strict;
use warnings;
use diagnostics;
use Date::Pcalc qw( Delta_Days );

our $g_file_log = "c:\\work\\jps.log";
our $g_file_log_tmp = "c:\\work\\jps.log.tmp";

sub cycle_log {

 my ( $cycle ) = @_;

 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
 #Because year is 2 digits and month starts at 0
 $year += 1900;
 $mon += 1;

 open(CFILE, "< ${g_file_log}") || die "Cannot open ${g_file_log} file\n";
 while (<CFILE>) {

  my @a = split / +/, $_;
  my ( $iyyyy, $imm, $idd ) = split /\//, $a[2];
  my $diff = Date::Pcalc::Delta_Days( $iyyyy, $imm, $idd , $year, $mon,
$mday, );

  if ( $diff >= $cycle ) {
   #print "Will be deleted because > $cycle days: $iyyyy, $imm, $idd \n";
   next;
  } else {
   open (my $file, ">>${g_file_log_tmp}") || return 2;

   ## code improvement part here ####
   my $string;
   foreach my $el ( @a ) {
    chomp ( $el );
    $string = $string . "${el} ";
   }

   $string =~ s/(^.+)(\s$)/$1/;
   $string = $string . "\n";
   print $file $string;
   close $file;
   ###################################
  }
 }
 close (CFILE) || die "Cannot close $g_file_log file\n";
}

sub main {
 &cycle_log( 2 );
}
main();
exit 0;




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

Date: Wed, 28 Jul 2004 17:09:07 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Efficiency in code to cycle log file
Message-Id: <280720041709074911%jgibson@mail.arc.nasa.gov>

In article <UwVNc.39538$vO1.194402@nnrp1.uunet.ca>, Domenico Discepola
<domenico_discepola@quadrachemicals.com> wrote:

> Hello.  I wrote a subroutine that creates log file entries in a text file
> using the following format: script name version date time status message.  A
> sample entry would be:
> 
> script v1.0.2 2004/07/12 12:29:18 (I): Message 1 here
> script v1.0.2 2004/07/12 12:29:48 (I): Message 2 here
> etc.
> 
> The important part is that the first 5 "fields" are space seperated whose
> positions will not change.  I now wanted to cycle the log file if the date
> of the log file entry was greater than a certain value, based on today's
> date.  In other words, delete all log file entries older than X days.  The
> code I posted works well enough for me but it is not very elegant.  Right
> now, the script simply creates a "temporary" file with the log file entries
> I want to keep, leaving the original file untouched.  I would consider it a
> learning experience if someone can provide me with some suggestions for
> tightening the code.

I can offer up some suggestions for 'improving' your program that, if
you had been reading this group for a few months, you would already
have read several times.


> #!perl
> use strict;
> use warnings;
> use diagnostics;
> use Date::Pcalc qw( Delta_Days );
> 
> our $g_file_log = "c:\\work\\jps.log";
> our $g_file_log_tmp = "c:\\work\\jps.log.tmp";

You are better off using single quotes here, because you are not doing
any interpolation of variables. With single quotes, you do not need to
escape the backslashes. Even better, use forwardslashes as perl lets
you do so.

> 
> sub cycle_log {
> 
>  my ( $cycle ) = @_;

You may also use:

   my $cycle = shift;

> 
>  my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
> localtime(time);
>  #Because year is 2 digits and month starts at 0

Actually, for the past four years $year has been 3 digits. :)

>  $year += 1900;
>  $mon += 1;
> 
>  open(CFILE, "< ${g_file_log}") || die "Cannot open ${g_file_log} file\n";

Better: use the 3 argument version of open and don't put the file name
in quotes. Add the reason the open failed to the die statement (special
variable $!) and delete the "\n" to get more info.

You should also open the output file here, too (see below).


>  while (<CFILE>) {
> 

Add
   chomp;
here (see below).

>   my @a = split / +/, $_;

Better would be:  my @a = split;

i.e., use the defaults that perl gives you.

>   my ( $iyyyy, $imm, $idd ) = split /\//, $a[2];

Use alternate delimiters on a regular expression to avoid having to
escape special characters:

   ... = split m|/|, $a[2];

You could also use the unpack function to extract the fixed-width,
fixed-location fields in one step. Something like (untested):

   my( $y, $m, $d ) = unpack('x14 A4 x A2 x A2', $_;


>   my $diff = Date::Pcalc::Delta_Days( $iyyyy, $imm, $idd , $year, $mon,
> $mday, );
> 
>   if ( $diff >= $cycle ) {
>    #print "Will be deleted because > $cycle days: $iyyyy, $imm, $idd \n";
>    next;
>   } else {
>    open (my $file, ">>${g_file_log_tmp}") || return 2;

Do you really want to reopen the file each time? That seems terribly
inefficient! Why not open the file before the loop?

> 
>    ## code improvement part here ####
>    my $string;
>    foreach my $el ( @a ) {
>     chomp ( $el );

Only the last element of the @a array will have a newline at the end.
Chomping all of the other elements is unnecessary and wasteful. Add the
chomp above and remove this one.

>     $string = $string . "${el} ";

You don't need the braces. "$el " works fine.

>    }
> 
>    $string =~ s/(^.+)(\s$)/$1/;

There is an easier way to trim blanks from the end of a line that
doesn't require capturing, evaluating an expression, anc substituting:

   $string =~ s/\s*$//;

>    $string = $string . "\n";
>    print $file $string;

You don't really need to decompose the line and then put it back
together to print it. You should probably replace your loop with:

   while( my $line = <CFILE> ) {
      ... # extract $diff from $line
      print $line if $diff >= $cycle;
   }

>    close $file;

Since you are now going to open the file before the loop, move the
close to after the loop, and check to see if the close works (usually
does, but checking it puts you in the top percentile of paranoid
programmers! :)

>    ###################################
>   }
>  }
>  close (CFILE) || die "Cannot close $g_file_log file\n";

Well, there you go. You are already in that top percentile! But
wouldn't you want to know the reason such a rare event occurred? (add
$! to your error message).

> }
> 
> sub main {
>  &cycle_log( 2 );
> }
> main();

Perl is not C. You don't need to define a main subroutine. Execution
will start with the first non-subroutine statement (usually).

> exit 0;

Exits are not required either, but they don't hurt.

I am sure others could offer even better suggestions, but I tried to
show you the easy stuff.


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

Date: 30 Jul 2004 04:29:55 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1091161771@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            and XEmacs port

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
        http://math.berkeley.edu/~ilya/software/emacs/
        by Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: 23 Jul 2004 07:38:35 -0700
From: klestes@nmhs.net (K. L. Estes)
Subject: Example code wanted for talking to Groupwise via IMAP4...
Message-Id: <5b63b266.0407230638.6b656fca@posting.google.com>

Or if anyone has any knowledge/lore about how to do this, I'm all ears !


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 6806
***************************************


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