[25736] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7976 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 15 00:10:25 2005

Date: Thu, 14 Apr 2005 21:10:18 -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           Thu, 14 Apr 2005     Volume: 10 Number: 7976

Today's topics:
        Net::LDAP <subs.nntp.wfitzgerald@crtman.com>
    Re: Net::LDAP <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Net::LDAP axel@white-eagle.invalid.uk
        Source Code for Beginning Perl by Simon Cozens  <mdetomaso@bak.rr.com>
    Re: Source Code for Beginning Perl by Simon Cozens  <ccolumbu@hotmail.com>
    Re: Source Code for Beginning Perl by Simon Cozens  <ccolumbu@hotmail.com>
    Re: Source Code for Beginning Perl by Simon Cozens  <mdetomaso@bak.rr.com>
    Re: suggestion for perlop (Anno Siegel)
    Re: Supercomputer and encryption and compression @ rate <nospam@bigpond.com>
        trouble with very simple regexp <spamtrap@Astrumtech.com>
    Re: trouble with very simple regexp <pilsl@goldfisch.at>
    Re: trouble with very simple regexp <matternc@comcast.net>
    Re: trouble with very simple regexp <Jeff.Stampes@xilinx.com>
    Re: trouble with very simple regexp ioneabu@yahoo.com
    Re: trouble with very simple regexp ioneabu@yahoo.com
    Re: trouble with very simple regexp ioneabu@yahoo.com
        using Perl module when host admin does not install it ? <jazeker_b_nospamlalala@yahoo.co.uk>
    Re: using Perl module when host admin does not install  <1usa@llenroc.ude.invalid>
    Re: using Perl module when host admin does not install  <tadmc@augustmail.com>
    Re: using Perl module when host admin does not install  <1usa@llenroc.ude.invalid>
    Re: using Perl module when host admin does not install  <asolkar@gmail.com>
        while loop into database insert not working <perlguru2b@bobotheclown.org>
    Re: while loop into database insert not working axel@white-eagle.invalid.uk
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 14 Apr 2005 16:22:59 -0400
From: Warrick FitzGerald <subs.nntp.wfitzgerald@crtman.com>
Subject: Net::LDAP
Message-Id: <EiA7e.62$6A4.584@news.uswest.net>

Hi All,

I have created a user in OpenLDAP which has a password set.

I'd like to bind to the LDAP server as this user using Net::LDAP, but
I'm having some problems figuring out if my bind was sucessful or not.

=========
use Net::LDAP;
$ldap = Net::LDAP->new( '10.10.40.40' );

# bind to a directory with dn and password
$mesg = $ldap->bind( 'uid=sporter,ou=People,dc=livetechnology,dc=com',
                      password => 'xxxxx'
 );

print $mesg."\n";
=========

Returns

Net::LDAP::Bind=HASH(0x8069c24)

but I get this response no matter what password I use ....

How can I tell if this is working or not? All I really want to see is if
this username and password combination works.


Thanks
Warrick


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

Date: Thu, 14 Apr 2005 23:10:18 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Net::LDAP
Message-Id: <425edc41$0$19333$8fcfb975@news.wanadoo.fr>

Warrick FitzGerald wrote:
<snip>

> use Net::LDAP;
> $ldap = Net::LDAP->new( '10.10.40.40' );
> 
> # bind to a directory with dn and password
> $mesg = $ldap->bind( 'uid=sporter,ou=People,dc=livetechnology,dc=com',
>                       password => 'xxxxx'
>  );
> 
> print $mesg."\n";
> =========
> 
> Returns
> 
> Net::LDAP::Bind=HASH(0x8069c24)
> 
> but I get this response no matter what password I use ....
> 
> How can I tell if this is working or not? All I really want to see is if
> this username and password combination works.


check out

perldoc Net::LDAP::Message

you want to do something like:

if($mesg->is_error()){
	my $errorMessage = $mesg->error();
# process failure
}

don't forget to run with

use strict;
use warnings;

Mark


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

Date: Thu, 14 Apr 2005 16:41:03 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Net::LDAP
Message-Id: <85GdnRPo-_ryfsPfRVn-rQ@adelphia.com>

Warrick FitzGerald <subs.nntp.wfitzgerald@crtman.com> wrote:
> I have created a user in OpenLDAP which has a password set.
> I'd like to bind to the LDAP server as this user using Net::LDAP, but
> I'm having some problems figuring out if my bind was sucessful or not.
 
> =========
> use Net::LDAP;
> $ldap = Net::LDAP->new( '10.10.40.40' );
> 
> # bind to a directory with dn and password
> $mesg = $ldap->bind( 'uid=sporter,ou=People,dc=livetechnology,dc=com',
>                      password => 'xxxxx'
> );
 
> print $mesg."\n";
> =========
 
> Returns
> Net::LDAP::Bind=HASH(0x8069c24)
> but I get this response no matter what password I use ....

> How can I tell if this is working or not? All I really want to see is if
> this username and password combination works.

You need to check $mesg->code. If this is non-zero then there is an
error and there should be a message in $mesg->error, e.g.

	die $mesg->error if $mesg->code;

Axel



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

Date: Thu, 14 Apr 2005 22:07:26 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: Source Code for Beginning Perl by Simon Cozens 
Message-Id: <yQB7e.6$K25.2@news-wrt-01.socal.rr.com>

I'm currently reading online the PDF's for Simon Cozens book:

http://learn.perl.org/library/beginning_perl/

Downloading the Source Code
---------------------------
 ...
Whether you want to type the code in or not, we have made all the source 
code available at our web site, at the following address: 
http://www.wrox.com

[14:57] <tomatoe> Q: I tried to find the source code from 
http://www.wrox.com Downloading the Source Code for Beginning Perl by Simon 
Cozens but can't find it.  Q: does it exist elsewhere ???

- Thanks & take care M.D.

<aka>

                    _                        _
                   | |_ ___  _ __ ___   __ _| |_ ___   ___
                   | __/ _ \| '_ ` _ \ / _` | __/ _ \ / _ \
                   | || (_) | | | | | | (_| | || (_) |  __/
                    \__\___/|_| |_| |_|\__,_|\__\___/ \___|





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

Date: Thu, 14 Apr 2005 15:14:40 -0700
From: "Chad Columbus" <ccolumbu@hotmail.com>
Subject: Re: Source Code for Beginning Perl by Simon Cozens 
Message-Id: <jXB7e.94$Zi.19@fed1read04>

Googled "Beginning Perl by Simon Cozens"
Found:
http://learn.perl.org/library/beginning_perl/

There are links on the right hand side:
Code Examples (Zip Format)
Code Examples (tar.gz Format)

-- 

^C


"Michael De Tomaso" <mdetomaso@bak.rr.com> wrote in message 
news:yQB7e.6$K25.2@news-wrt-01.socal.rr.com...
> I'm currently reading online the PDF's for Simon Cozens book:
>
> http://learn.perl.org/library/beginning_perl/
>
> Downloading the Source Code
> ---------------------------
> ...
> Whether you want to type the code in or not, we have made all the source code 
> available at our web site, at the following address: http://www.wrox.com
>
> [14:57] <tomatoe> Q: I tried to find the source code from http://www.wrox.com 
> Downloading the Source Code for Beginning Perl by Simon Cozens but can't find 
> it.  Q: does it exist elsewhere ???
>
> - Thanks & take care M.D.
>
> <aka>
>
>                    _                        _
>                   | |_ ___  _ __ ___   __ _| |_ ___   ___
>                   | __/ _ \| '_ ` _ \ / _` | __/ _ \ / _ \
>                   | || (_) | | | | | | (_| | || (_) |  __/
>                    \__\___/|_| |_| |_|\__,_|\__\___/ \___|
>
>
> 



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

Date: Thu, 14 Apr 2005 15:23:51 -0700
From: "Chad Columbus" <ccolumbu@hotmail.com>
Subject: Re: Source Code for Beginning Perl by Simon Cozens 
Message-Id: <V3C7e.95$Zi.54@fed1read04>

> "Michael De Tomaso" <mdetomaso@bak.rr.com> wrote in message 
> news:yQB7e.6$K25.2@news-wrt-01.socal.rr.com...
>> I'm currently reading online the PDF's for Simon Cozens book:
>>
>> http://learn.perl.org/library/beginning_perl/
>>
>> Downloading the Source Code
>> ---------------------------
>> ...
>> Whether you want to type the code in or not, we have made all the source code 
>> available at our web site, at the following address: http://www.wrox.com
>>
>> [14:57] <tomatoe> Q: I tried to find the source code from http://www.wrox.com 
>> Downloading the Source Code for Beginning Perl by Simon Cozens but can't find 
>> it.  Q: does it exist elsewhere ???

"Chad Columbus" <ccolumbu@hotmail.com> wrote in message 
news:jXB7e.94$Zi.19@fed1read04...
> Googled "Beginning Perl by Simon Cozens"
> Found:
> http://learn.perl.org/library/beginning_perl/
>
> There are links on the right hand side:
> Code Examples (Zip Format)
> Code Examples (tar.gz Format)
>
> -- 
>
> ^C

Sorry group, didn't mean to top post.
^C



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

Date: Thu, 14 Apr 2005 22:50:01 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: Re: Source Code for Beginning Perl by Simon Cozens 
Message-Id: <tsC7e.8$K25.3@news-wrt-01.socal.rr.com>

Answer:

 #perl  via IRC
=======
[15:00] <black-ice> tomatoe, http://learn.perl.org/library/beginning_perl/ 
specificly.
[15:41] <tomatoe> ty, black-ice
[15:41] <tomatoe> gee, U'd think I'd look @ the whole TOC: Code Examples 
(Zip Format)
[15:41] <tomatoe> Code Examples (tar.gz Format)
[15:42] <tomatoe> they were at the end of the Table of Contents, etc.
[15:44] <tomatoe> http://learn.perl.org/library/beginning_perl/3145.zip

 ... Egg on Face, but hey, I was hungry :)

10/4 M.D.

"Michael De Tomaso" <mdetomaso@bak.rr.com> wrote in message news:...
> I'm currently reading online the PDF's for Simon Cozens book:
>
> http://learn.perl.org/library/beginning_perl/
>
> Downloading the Source Code
> ---------------------------
> ...
> Whether you want to type the code in or not, we have made all the source 
> code available at our web site, at the following address: 
> http://www.wrox.com
>
> [14:57] <tomatoe> Q: I tried to find the source code from 
> http://www.wrox.com Downloading the Source Code for Beginning Perl by 
> Simon Cozens but can't find it.  Q: does it exist elsewhere ???
>
> - Thanks & take care M.D.
>
> <aka>
>
>                    _                        _
>                   | |_ ___  _ __ ___   __ _| |_ ___   ___
>                   | __/ _ \| '_ ` _ \ / _` | __/ _ \ / _ \
>                   | || (_) | | | | | | (_| | || (_) |  __/
>                    \__\___/|_| |_| |_|\__,_|\__\___/ \___|
>
>
> 




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

Date: 14 Apr 2005 22:23:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: suggestion for perlop
Message-Id: <d3mqh8$10g$2@mamenchi.zrz.TU-Berlin.DE>

Hendrik Maryns  <hendrik_maryns@despammed.com> wrote in comp.lang.perl.misc:
> Anno Siegel uitte de volgende tekst op 14/04/2005 10:47:
> > Hendrik Maryns  <hendrik_maryns@despammed.com> wrote in comp.lang.perl.misc:
> > 
> >>Hi,
> >>
> >>I'm reading through perlop, and encountered the following:
> >>
> >>---------
> >>Unary ``+'' has no effect whatsoever, even on strings. It is useful 
> >>syntactically for separating a function name from a parenthesized 
> >>expression that would otherwise be interpreted as the complete list of 
> >>function arguments. (See examples above under Terms and List Operators 
> >>(Leftward).)
> >>---------
> >>
> >>But in Terms and List Operators, + is not used (as far as I can tell). 
> >>Instead, it is used in the section Named Unary Operators.  I suppose 
> >>this should be changed.
> > 
> > 
> > The section "Terms and List Operators (Leftward)" is split into sub-
> > sections "The Arrow Operator", "Auto-increment and Auto-decrement" and
> > so on.  The ninth of these is "Named Unary Operators", which is thus
> > part of "Terms and List Operators (Leftward)".
> > 
> > The structure is less than clear in the pod, where the section and
> > its subsections are all marked up as "=head2".  A look at the printed
> > version in the Camel (identically structured) makes the intention
> > clear.  Perhaps the subsections should become "=head3", but I'd hesitate
> > to suggest this without a close look at how "=headN" is used throughout
> > the perldoc pods.
> 
> I see.  In the offline html versions I'm looking at, (provided by 
> ActivePerl) there's no difference visible at all.

Sure, they are derived from the same pod, which fails to make a difference
between sections and subsections.  Read in context, the intention is
pretty clear, but for reference usage something is amiss.  To repair
it properly, one would have to look through (the core of) the pod files
for similar situations, then either adapt a solution found there, or
repair all cases in a similar manner.  It may be a singular case, but
you'd have to make sure.  Local damage control wouldn't do the Perl
documentation as a whole much good.

Anno


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

Date: Fri, 15 Apr 2005 06:04:53 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Supercomputer and encryption and compression @ rate of 96%
Message-Id: <425ecdb0@x-privat.org>

c3poptuse@yahoo.com wrote:

> Supercomputer and encryption and compression @ rate of 96%
> 
> Take a document then or a 3D matrix document change it two random or
> binary code

http://www.americanscientist.org/template/AssetDetail/assetid/20829/page/4
" The prevailing definition of randomness was formulated in the 1960s by
Gregory J. Chaitin of IBM and by the Russian mathematician A. N.
Kolmogorov. The definition says that a sequence of bits is random if the
shortest computer program for generating the sequence is at least as long
as the sequence itself."


Do you do squaring the circle and trisecting angles too?

gtoomey


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

Date: Thu, 14 Apr 2005 14:22:00 -0400
From: "BerkHolz, Steven" <spamtrap@Astrumtech.com>
Subject: trouble with very simple regexp
Message-Id: <425eb5bc@x-privat.org>

OK, I assume this is simple, but I haven't figured it out yet.

I want to find joeblow, joe-blow or joe_blow.

I am using two regexps:
joeblow
joe[_-]blow

What do I use to match this in one regexp?



-- 
Steven BerkHolz
Send to Domain TESCOGroup dot com, username SB

Note: you may also want to know that you should never send mail to:
blacklist-my-ip@admins.ws
info@dautrap.uceprotect.net
listme@sorbs.net
spamtrap@sandes.dk
spamtrap@stop.mail-abuse.org
spamtrap@frankenbiker.de
spamtrap@blars.org 




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

Date: Thu, 14 Apr 2005 20:37:56 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: Re: trouble with very simple regexp
Message-Id: <425eb88f$0$1942$79720d31@newsreader.inode.at>

BerkHolz, Steven wrote:
> 
> I want to find joeblow, joe-blow or joe_blow.
> 
> I am using two regexps:
> joeblow
> joe[_-]blow
> 
> What do I use to match this in one regexp?
> 

joe[_-]?blow
or
joe(_|-)?blow

best,
peter


-- 
http://www.goldfisch.at/know_list


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

Date: Thu, 14 Apr 2005 15:02:12 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: trouble with very simple regexp
Message-Id: <0JednfYJrKGpI8PfRVn-og@comcast.com>

BerkHolz, Steven wrote:

> OK, I assume this is simple, but I haven't figured it out yet.
> 
> I want to find joeblow, joe-blow or joe_blow.
> 
> I am using two regexps:
> joeblow
> joe[_-]blow
> 
> What do I use to match this in one regexp?
> 
joe[_-]?blow

The ? metacharacter indicates that the character class [_-] should
be matched zero or one times.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Thu, 14 Apr 2005 13:02:43 -0600
From: Jeff Stampes <Jeff.Stampes@xilinx.com>
Subject: Re: trouble with very simple regexp
Message-Id: <d3meoj$jaq3@cliff.xsj.xilinx.com>

peter pilsl wrote:
> BerkHolz, Steven wrote:
>> I want to find joeblow, joe-blow or joe_blow.
>>
>> I am using two regexps:
>> joeblow
>> joe[_-]blow
>>
>> What do I use to match this in one regexp?
> 
> joe[_-]?blow
> or
> joe(_|-)?blow

Or assuming you're not really needing to capture what comes between 
them, and you want to be more careful about getting exactly what you're 
looking for (instead of 'gottagojoe-blowhard')

/\bjoe(?:_|-)?blow\b/


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

Date: 14 Apr 2005 19:31:03 -0700
From: ioneabu@yahoo.com
Subject: Re: trouble with very simple regexp
Message-Id: <1113532263.676856.208560@f14g2000cwb.googlegroups.com>


BerkHolz, Steven wrote:
> OK, I assume this is simple, but I haven't figured it out yet.
>
> I want to find joeblow, joe-blow or joe_blow.

/joe.*blow/

Will match all of the above.  What do you not want to find?

wana



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

Date: 14 Apr 2005 19:31:27 -0700
From: ioneabu@yahoo.com
Subject: Re: trouble with very simple regexp
Message-Id: <1113532287.844120.145720@z14g2000cwz.googlegroups.com>


BerkHolz, Steven wrote:
> OK, I assume this is simple, but I haven't figured it out yet.
>
> I want to find joeblow, joe-blow or joe_blow.

/joe.*blow/

Will match all of the above.  What do you not want to find?

wana



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

Date: 14 Apr 2005 19:31:38 -0700
From: ioneabu@yahoo.com
Subject: Re: trouble with very simple regexp
Message-Id: <1113532298.662220.223910@o13g2000cwo.googlegroups.com>


BerkHolz, Steven wrote:
> OK, I assume this is simple, but I haven't figured it out yet.
>
> I want to find joeblow, joe-blow or joe_blow.

/joe.*blow/

Will match all of the above.  What do you not want to find?

wana



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

Date: Thu, 14 Apr 2005 20:15:27 GMT
From: Jazeker <jazeker_b_nospamlalala@yahoo.co.uk>
Subject: using Perl module when host admin does not install it ?
Message-Id: <zbA7e.64914$Ji2.4665417@phobos.telenet-ops.be>

Hello,

Sorry if this question has been asked before.  I was wondering if I 
could use a Perl module when your host is not inclined to do any 
installs for you.  I need CSV_XS for a test project, but my hosting 
company does not have it installed and they do not support their Perl 
functionality.

Is there a way to put the package somewhere in my hosting space and lure 
Perl into using it ?

Thank you
-- 
print <<EOF;
   Just a noobish Perl hacker
EOF


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

Date: Thu, 14 Apr 2005 21:52:28 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: using Perl module when host admin does not install it ?
Message-Id: <Xns9638B5C408DC9asu1cornelledu@127.0.0.1>

Jazeker <jazeker_b_nospamlalala@yahoo.co.uk> wrote in news:zbA7e.64914
$Ji2.4665417@phobos.telenet-ops.be:

> Sorry if this question has been asked before.  I was wondering if I 
> could use a Perl module when your host is not inclined to do any 
> installs for you.  I need CSV_XS for a test project, but my hosting 
> company does not have it installed and they do not support their Perl 
> functionality.

If you have shell access (so that you can compile the XS code),

> Is there a way to put the package somewhere in my hosting space and lure 
> Perl into using it ?

perldoc -q use

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Thu, 14 Apr 2005 17:35:22 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: using Perl module when host admin does not install it ?
Message-Id: <slrnd5ts1a.974.tadmc@magna.augustmail.com>

Jazeker <jazeker_b_nospamlalala@yahoo.co.uk> wrote:

> Sorry if this question has been asked before.  


There is no need to apologize for asking an already-asked question.

There is however, a need to apologize for asking a Frequently
Asked Question (like yours).

You should check the Perl FAQ *before* posting to the Perl newsgroup.


> I was wondering if I 
> could use a Perl module when your host is not inclined to do any 
> installs for you.  I need CSV_XS 
                                ^^
                                ^^

Then you will need access to a C compiler to install the module.


> for a test project, but my hosting 
> company does not have it installed and they do not support their Perl 
> functionality.
> 
> Is there a way to put the package somewhere in my hosting space and lure 
> Perl into using it ?


   perldoc -q module

       How do I install a module from CPAN?

       How do I keep my own module/library directory?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 14 Apr 2005 23:07:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: using Perl module when host admin does not install it ?
Message-Id: <Xns9638C28BE6D04asu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns9638B5C408DC9asu1cornelledu@127.0.0.1: 

> Jazeker <jazeker_b_nospamlalala@yahoo.co.uk> wrote in news:zbA7e.64914
> $Ji2.4665417@phobos.telenet-ops.be:

 ...

>> Is there a way to put the package somewhere in my hosting space and
>> lure Perl into using it ?
> 
> perldoc -q use

Ooops! I meant 

perldoc -q lib

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Thu, 14 Apr 2005 16:31:59 -0700
From: Mahesh A <asolkar@gmail.com>
Subject: Re: using Perl module when host admin does not install it ?
Message-Id: <115tvbg863kbjb8@corp.supernews.com>

Jazeker wrote:
> Sorry if this question has been asked before.  I was wondering if I 
> could use a Perl module when your host is not inclined to do any 
> installs for you.  I need CSV_XS for a test project, but my hosting 
> company does not have it installed and they do not support their Perl 
> functionality.
> 

I had similar problem installing XML::Simple module on my host. My host 
  had only a limited shell access. None of the 'make' utilities were 
accessible to me. As a result, I could not install modules on the host.

Instead, I installed the module locally, then FTP'd all the installed 
files to my hosting space.

     perldoc -q "own module"

Since XML::Simple required some C compilation, the machine I used for 
local installation had to be of a flavor similar to the host (for the 
compiled code to work).

> Is there a way to put the package somewhere in my hosting space and lure 
> Perl into using it ?

The FAQ mentioned above addresses this part.

I am not sure if this is the cleanest way of solving this problem, but 
it has worked for me - so far.

HTH,
Mahesh.
-- 
Mahesh Asolkar
asolkar-at-gmail-dot-com


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

Date: Thu, 14 Apr 2005 23:49:35 GMT
From: Unknown <perlguru2b@bobotheclown.org>
Subject: while loop into database insert not working
Message-Id: <pan.2005.04.14.23.55.07.563455@bobotheclown.org>

Hello All,

 I am working on this script which will parse several Backup Exec logs
 and place key details into a database for viewing as statistics
 on a web based front end.  I posted all the code, but I am only having
 trouble with the while loop (inside the foreach). It is not behaving the
 way I expect it to in that it prints several copies of each record
 instea of just one record for one text file.

thanks
Rocky 



#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use DBD::Pg;

my $filedir = '/var/backuplogs';
my $servername;
my $jobname;
my $jobstarted;
my $medialabel;
my $logfile;
my $jobended;
my $status;
my @inuse;
my @skipped;
my @corrupt;
my @skippednames;
my $skipped;
my $corrupt;
my $inuse;


opendir(DIR, $filedir) or die "could not open logfile directory: $!";
my @filestoparse =  grep { /\.txt$/ } readdir(DIR);
closedir(DIR);

foreach my $filename (@filestoparse)    {
my $complete = "$filedir/" . "$filename";
open(FH, "$complete") or die "Cannot find file $complete: $!";
while (<FH>)    {
if ($_ =~ /^Job\sserver:\s+(.*)$/)              { $servername = $1;}
if ($_ =~ /^Job\sname:\s+(.*)$/)                { $jobname = $1;}
if ($_ =~ /^Job\sstarted:\s+(.*)$/)             { $jobstarted = $1;}
if ($_ =~ /^Media.*Label:\s+(.*)$/)             { $medialabel = $1;}
if ($_ =~ /^Job\sended:\s+(.*)$/)               { $jobended = $1;}
if ($_ =~ /^Job\scompletion\sstatus:\s+(.*)$/)  { $status = $1;}
if ($_ =~ /^(\d+)\s+files\swere\sin.*$/)        {push(@inuse, $1);}
if ($_ =~ /^(\d+)\s+items/)                     {push(@skipped, $1);}
if ($_ =~ /^(\d+)\s+corrupt/)                   {push(@corrupt, $1);}
if ($_ =~ /^.*item(.*\s-\sskipped.*)$/)         {push(@skippednames, $1);}

$corrupt = &addnums(@corrupt);
$skipped = &addnums(@skipped);
$inuse = &addnums(@inuse);
$logfile = $filename;

        }
close(FH);
print "$jobname,$jobstarted,$logfile,$servername\n";

my $dbh = DBI->connect( "dbi:Pg:dbname=backup", "[snip]", "[snip]") or die
"Cannot connect to PGSQL DB\n"; my $sth = $dbh->prepare("INSERT INTO
backuplogs(jobname,jobstarted,logfile,servername,status,inuse,jobended,skipped,corrupt,medialabel,testlogfile)
VALUES
('$jobname','$jobstarted','$logfile','$servername','$status','$inuse','$jobended','$skipped','$corrupt','$medialabel','<a
href=http://[snip]/oldlogs/$logfile>$logfile</a>')")
or die "Error preparing row: $DBI::errstr\n"; $sth->execute() or die "
$DBI::errstr\n"; $dbh->disconnect;
$servername = "";
$jobname = "";
$jobstarted = "";
$medialabel = "";
$jobended = "";
$status = "";
}


sub addnums {
my @number = @_;
my $total;
my $digit;
foreach $digit (@number)        {
$total += $digit;
}

if (defined($total))    {
$total  = $total;
}
else
{$total = 0;}
return $total;
}




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

Date: Thu, 14 Apr 2005 20:09:57 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: while loop into database insert not working
Message-Id: <mNCdnR-C67H4icLfRVn-rA@adelphia.com>

Unknown <perlguru2b@bobotheclown.org> wrote:
> I am working on this script which will parse several Backup Exec logs
> and place key details into a database for viewing as statistics
> on a web based front end.  I posted all the code, but I am only having
> trouble with the while loop (inside the foreach). It is not behaving the
> way I expect it to in that it prints several copies of each record
> instea of just one record for one text file.

I can see nothing obviously wrong with it... although the while loop has
no print statements - the only print statement is within the foreach
loop.
 
> foreach my $filename (@filestoparse)    {
> my $complete = "$filedir/" . "$filename";
> open(FH, "$complete") or die "Cannot find file $complete: $!";
> while (<FH>)    {
> [snip]
>        }
> close(FH);
> print "$jobname,$jobstarted,$logfile,$servername\n";
 
In such cases I would place a few diagnostic print statements to make
sure that your data is what you are expecting - e.g. the list of files
to be opened and so on.

Axel



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

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 7976
***************************************


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