[24096] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6290 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 14:05:48 2004

Date: Mon, 22 Mar 2004 11:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 22 Mar 2004     Volume: 10 Number: 6290

Today's topics:
    Re: Accessing a SQL Server Database from a Perl Script  <mpeppler@peppler.org>
    Re: Capturing errors from sqlplus <jwillmore@remove.adelphia.net>
    Re: Capturing errors from sqlplus ctcgag@hotmail.com
    Re: DBI selectall_hashref problem <ThomasKratz@REMOVEwebCAPS.de>
    Re: DBI selectall_hashref problem <ittyspam@yahoo.com>
    Re: How to determine the path of a module? <jwillmore@remove.adelphia.net>
    Re: How to determine the path of a module? (Randal L. Schwartz)
        Memory, perl, and Linux (Myron Turner)
    Re: perl threads Thread Queue <mail@mail.com>
        selfmade scripts <anonymous@disneyland.com>
    Re: selfmade scripts <nobull@mail.com>
    Re: selfmade scripts <anonymous@disneyland.com>
    Re: selfmade scripts <ittyspam@yahoo.com>
    Re: selfmade scripts <anonymous@disneyland.com>
    Re: selfmade scripts <ittyspam@yahoo.com>
    Re: selfmade scripts <sbryce@scottbryce.com>
    Re: using a variable as STDIN for an external program (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 22 Mar 2004 09:58:58 -0800
From: Michael Peppler <mpeppler@peppler.org>
Subject: Re: Accessing a SQL Server Database from a Perl Script on Linux
Message-Id: <pan.2004.03.22.17.58.58.457472@peppler.org>

On Mon, 22 Mar 2004 05:15:11 -0800, v796 wrote:

> Hi,
> I got the DBD Syabase tar file from your website. But I have no clue how
> to install it. I went thru  the README and am confused. I don't have any
> Sybase directory on my system, neither is the env. variable set. I am
> using Linux.

Well - the SYBASE env. variable would normally point to the Sybase
installation - but if you intend to connect to MS-SQL then you need
FreeTDS instead of Sybase. 

> The MS SQL Server Database is on a Windows machine for which I have only
> read permissions. I am assuming that what works with Sybase will work
> with MS SQL Server too.
> 
> Please help on this installation. Also I plan to install FreeTDS instead
> of Sybase OpenClient libraries. I think that will be less painful.

Start by installing FreeTDS - without it you *can't* use DBD::Sybase to
access MS-SQL.

Michael

> Michael Peppler <mpeppler@peppler.org> wrote in message
> news:<pan.2004.03.20.17.44.25.571388@peppler.org>...
>> On Fri, 19 Mar 2004 18:22:04 +0000, Stephen Patterson wrote:
>> 
>> > On Fri, 19 Mar 2004 04:04:50 GMT, Bob Walton wrote:
>> >>     use DBI;
>> > 
>> > With DBD::Sybase - we use this at work for some daily reports.
>> 
>> But don't forget that you need FreeTDS (www.freetds.org) as well.
>> 
>> Michael

-- 
Michael Peppler                              Data Migrations, Inc.
mpeppler@peppler.org                       http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or 
long term contract positions - http://www.peppler.org/resume.html



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

Date: Mon, 22 Mar 2004 10:34:01 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Capturing errors from sqlplus
Message-Id: <pan.2004.03.22.15.34.00.162306@remove.adelphia.net>

On Sun, 21 Mar 2004 19:56:19 -0800, David wrote:

> I'm piping a bunch of insert statements through sqlplus (yes, I know I
> should be using the DBI or sql*loader, unfortunately I can't either)
> and I'm having trouble capturing errors when they happen.
> 
> For example, if I try and insert a row with a duplicate primary key, I
> get this error on the terminal ...
> 
> ERROR at line 1:
> ORA-00001: unique constraint (OPS$N450MAT.INTERFACE_PK) violated
> 
> The return code however is 0 ...
> 
> DEBUG: return code $? = 0

Have you used another scripting language or shell to see if sqlplus
returns something other than zero when this "error" is encountered?
 
[ ... ]

>   print SQL <<EOR;
> $sql
> commit;
> exit
> EOR
> 
> close SQL or warn ("Couldn't close sqlplus pipe: $!"); print "DEBUG:
> return code \$\? is $?\n";

You're trying to commit the transaction, but I didn't see any "BEGIN" at
the start of the transaction.  Doesn't Oracle need this?

Where I work, I've noticed that the output from the sqlplus command is
redirected to a file and then 'grep'ed for an error.  Maybe this is the
direction you need to proceed in?

OTOH, why not just use the DBI module with the DBD::Oracle driver :-)

Just some random thoughts ....

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Old age is the most unexpected of things that can happen to a
man.   -- Trotsky 



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

Date: 22 Mar 2004 16:35:00 GMT
From: ctcgag@hotmail.com
Subject: Re: Capturing errors from sqlplus
Message-Id: <20040322113500.494$WB@newsreader.com>

davidol@hushmail.com (David) wrote:
> I'm piping a bunch of insert statements through sqlplus (yes, I know I
> should be using the DBI or sql*loader, unfortunately I can't either)
> and I'm having trouble capturing errors when they happen.

Why can't you?

> For example, if I try and insert a row with a duplicate primary key, I
> get this error on the terminal ...
>
> ERROR at line 1:
> ORA-00001: unique constraint (OPS$N450MAT.INTERFACE_PK) violated

Does it appear on your terminal through STDOUT, STDERR, or neither of
these?

I think it is probably through STDOUT.


> The return code however is 0 ...


SQLPLUS did not suffer an error, it merely reported an error
that occured elsewhere, and continued on with its other duties,
so it should return 0.

>
> DEBUG: return code $? = 0
>
> How can I capture sqlplus errors from within the script?  An extract
> of the code is below ...

Redirect STDOUT and/or STDERR to a file, and parse that file

Or use open2 or open3 to pipe STDOUT/STDERR back into the script.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Mon, 22 Mar 2004 16:40:55 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: DBI selectall_hashref problem
Message-Id: <405f0a33.0@juno.wiesbaden.netsurf.de>

James Szinger wrote:

> 
>     # scalar: retrieve temp_high for $address
>     my $sql = 'SELECT temp_high FROM settings WHERE address=?';
>     my $sth = $dbh->prepare($sql);
>     $sth->execute( $address);
>     my $temp_high = $sth->fetchrow_array();
>     $sth->finish();
> 
> or
> 
>     # simple hash: key=address, value=temp_high
>     my $sql = 'SELECT address, temp_high FROM settings';
>     my $sth = $dbh->prepare($sql);
>     $sth->execute();
>     my %temp_high = map { $_->[0] => $_->[1] } @{ $sth->fetchall_arrayref()};

Not exactly for this task but more for general DBI use, I would recommend 
using fetchall_arrayref with a hashref as parameter, which results in an 
more intuitive AoH representation of a table or result set.

as in:

    my $sql = 'SELECT address, temp_high FROM settings';
    my $sth = $dbh->prepare($sql);
    $sth->execute();
    my $result = $sth->fetchall_arrayref( {} );

Then dumping $result would give:

$VAR1 = [
    {
       'temp_high' => '60',
       'address' => '7F4B15000000'
    },
    {
       'temp_high' => '85',
       'address' => '3ACA50000000'
    }
];

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


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

Date: Mon, 22 Mar 2004 11:22:58 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: DBI selectall_hashref problem
Message-Id: <20040322112102.X21521@dishwasher.cs.rpi.edu>

On Fri, 19 Mar 2004, Jim Canfield wrote:

> > > Here is the output of Data::Dumper ....really cool by BTW!
> > >
> > > $VAR1 = {
> > > '7F4B15000000' => {
> > > 'temp_high' => '60',
> > > 'address' => '7F4B15000000'
> > > },
> > > '3ACA50000000' => {
> > > 'temp_high' => '85',
> > > 'address' => '3ACA50000000'
> > > }
> > > };
> > >
> > Okay, and what have you learned from this output?  Do you see that the
> > $max variable is a hashref of hashrefs?  This is exactly as what you
> > should expect by calling the method "selectall_hashref".  And yet you're
> > trying to access a hashref of arrays.  Obviously, this will not work.
> >
> > print $max->{$address}{'temp_high'}; #Print the max temp
> >
> > Paul Lalli
>
> So, what should I use other than "selectall_hashref" to bring things up a
> level?

 ... what makes you think you can't use selectall_hashref?  Just use it
correctly.  If you prefer, you can use selectall_arrayref instead, as
others have suggested.

> Also, just out of curiosity, does this mean the example in the "Perl
> Cookbook" is wrong?

Without seeing the example you're referring to, there's no way for me to
know the answer to that, though I rather doubt it.

Paul Lalli


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

Date: Mon, 22 Mar 2004 10:40:16 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: How to determine the path of a module?
Message-Id: <pan.2004.03.22.15.40.14.361364@remove.adelphia.net>

On Mon, 22 Mar 2004 10:56:02 +0000, Guru03 wrote:

> Hi, I need to know the path of a PERL module inside a Perl program.
> i.e. I want to know the location of 'date.pm'.
> 
> What's the easiest way to do it?

If, for some reason, you need to know the location of a '.pm' file, use
perldoc with the '-l' option.

For example: perldoc -l CGI
will give the location of the CGI.pm file.

There are other ways as others have mentioned.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Naeser's Law:  You can make it foolproof, but you can't make it
<damnfoolproof. 



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

Date: Mon, 22 Mar 2004 16:26:30 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How to determine the path of a module?
Message-Id: <4136dc4479d10b17fae79b3460186274@news.teranews.com>

>>>>> "James" == James Willmore <jwillmore@remove.adelphia.net> writes:

James> If, for some reason, you need to know the location of a '.pm' file, use
James> perldoc with the '-l' option.

James> For example: perldoc -l CGI
James> will give the location of the CGI.pm file.

This works as long as the docs are embedded.  If there are no embedded
docs, the command fails.  If the docs are in a separate ".pod" file,
you get that path instead.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 22 Mar 2004 17:11:22 GMT
From: mturner@ms.umanitoba.ca (Myron Turner)
Subject: Memory, perl, and Linux
Message-Id: <405f1d82.1605209499@news.wp.shawcable.net>


I've written a perl module, currently in use,  which does asynchronous
searches of library databases anywhere in the world.  It forks off a
separate process for each database which it contacts.  In the past
I've had it search successfuly through more than 1000 databases,
reporting back one one record from each.

The processes are forked out 5 at a time, every 25 seconds.  The
forked  processes are controlled by Event timers, so that they time
out after  20 seconds,  if they can't connect to the server they are
supposed to query.   But if they do connect, they are left in play.
This means that a backlog of forked processes cand build up while
waiting to get the records they've requested, especially when querying
large numbers.
  
Each record averages about 1k .  There is, in addition, about 5k
overhead for each forked process.  Recently, I've wanted to use this
module to again query upwards of 1000 databases but to bring back
between 10 and 25 records.  So, we now have as much as 30k devoted to
each forked process.   The result was a great deal of disk thrashing
and repeated reports to the terminal from the operating system that it
it was out of memory and had killed one of the forked processes.
During this time the terminal was essentially locked and wouldn't
respond to the keyboard, so there was nothing I could do but wait or
reboot.   The disk thrashing I assuming was a sign of memory swapping.


I tried to solve the problem by running a pipe from Linux's top
command in the main program before forking off each batch of 5 forked
processes.  I examined the outupt from top to determined whether the
main process had gone above 60% of memory capacity.  If so, I
implement a 5 minute timeout period.  This worked like a charm.  But
when I looked at what was really happening, it turned out that the
sleep period never had to be set.  Memory never exceeded about 5% of
the total memory resources.

So, I thought, maybe it just needs the extra time between each batch
of 5 forks.  Instead of using the pipe to top, I implemented a 60
second timeout between each batch of 5 forks.  This was better than
nothing but there was nevertheless a significant memory drain and
eventually the terminal froze.    By using the ps command I could see
that there was a huge backlog of forked processes in memory--this was
not the case when I used top.  And the access to top took only 6
seconds.

So, it seems that ther's something soothing to the operating system in
running the external program--top--which has nothing to do with giving
the system more time to processes the forks.

I'd appreciate any help in solving this mystery, so that I don't just
blindly insert a pipe to top without knowing what's happening.

Thanks.

Myron Turner
www.room535.org


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

Date: Mon, 22 Mar 2004 15:00:12 -0000
From: "bob" <mail@mail.com>
Subject: Re: perl threads Thread Queue
Message-Id: <JP6dnSzENM5WYsPdSa8jmA@karoo.co.uk>

Just for future information

Thread::Queue::Any alows the passing of any kind of referance
"bob" <mail@mail.com> wrote in message
news:aM6dnYaf5KdTT8PdSa8jmA@karoo.co.uk...
> Would anyone have an example of passing a hash to a thread queue??
> I have tried passing it as a ref but all i so far can do is pass scalars
> i.e. 1,2,3,4,5
>
> When testing i keep getting
>
> Invalid value for shared scalar at
> /usr/local/lib/perl5/5.8.3/Thread/Queue.pm line 90.
> Thanks in advance
>
>




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

Date: Mon, 22 Mar 2004 17:18:19 GMT
From: "luc" <anonymous@disneyland.com>
Subject: selfmade scripts
Message-Id: <vdF7c.45503$fd.3087488@phobos.telenet-ops.be>

Is there a site somewhere where I can put my own perl scripts?




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

Date: 22 Mar 2004 17:28:06 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: selfmade scripts
Message-Id: <u9vfkwg5aw.fsf@wcl-l.bham.ac.uk>

"luc" <anonymous@disneyland.com> writes:

> Is there a site somewhere where I can put my own perl scripts?

This would depend on what they do and why you want to put them on a
site.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 22 Mar 2004 18:26:46 GMT
From: "luc" <anonymous@disneyland.com>
Subject: Re: selfmade scripts
Message-Id: <GdG7c.45578$Hs1.3223592@phobos.telenet-ops.be>


"Brian McCauley" <nobull@mail.com> schreef in bericht
news:u9vfkwg5aw.fsf@wcl-l.bham.ac.uk...
> "luc" <anonymous@disneyland.com> writes:
>
> > Is there a site somewhere where I can put my own perl scripts?
>
> This would depend on what they do and why you want to put them on a
> site.

just an ordinary script that processes some form data.




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

Date: Mon, 22 Mar 2004 13:32:22 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: selfmade scripts
Message-Id: <20040322133121.Q21521@dishwasher.cs.rpi.edu>

On Mon, 22 Mar 2004, luc wrote:

> "Brian McCauley" <nobull@mail.com> schreef in bericht
> news:u9vfkwg5aw.fsf@wcl-l.bham.ac.uk...
> > "luc" <anonymous@disneyland.com> writes:
> >
> > > Is there a site somewhere where I can put my own perl scripts?
> >
> > This would depend on what they do and why you want to put them on a
> > site.
>
> just an ordinary script that processes some form data.


Are you asking for a location to put your own CGI scripts for your own
personal use?  Or for a respository of Perl scripts where people can store
scripts they've written for others to download and use?

Paul Lalli


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

Date: Mon, 22 Mar 2004 18:39:35 GMT
From: "luc" <anonymous@disneyland.com>
Subject: Re: selfmade scripts
Message-Id: <HpG7c.45595$g52.3284073@phobos.telenet-ops.be>


"Paul Lalli" <ittyspam@yahoo.com> schreef in bericht
news:20040322133121.Q21521@dishwasher.cs.rpi.edu...
> On Mon, 22 Mar 2004, luc wrote:
>
> > "Brian McCauley" <nobull@mail.com> schreef in bericht
> > news:u9vfkwg5aw.fsf@wcl-l.bham.ac.uk...
> > > "luc" <anonymous@disneyland.com> writes:
> > >
> > > > Is there a site somewhere where I can put my own perl scripts?
> > >
> > > This would depend on what they do and why you want to put them on a
> > > site.
> >
> > just an ordinary script that processes some form data.
>
>
> Are you asking for a location to put your own CGI scripts for your own
> personal use?  Or for a respository of Perl scripts where people can store
> scripts they've written for others to download and use?
>
> Paul Lalli

It would be a script to process a form for a site I made but I cant put it
on my site's server so I thought maybe to put it somewhere else and then in
my html code put a link to it.




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

Date: Mon, 22 Mar 2004 14:01:01 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: selfmade scripts
Message-Id: <20040322135922.V21521@dishwasher.cs.rpi.edu>

On Mon, 22 Mar 2004, luc wrote:

> "Paul Lalli" <ittyspam@yahoo.com> schreef in bericht
> news:20040322133121.Q21521@dishwasher.cs.rpi.edu...
> > On Mon, 22 Mar 2004, luc wrote:
> >
> > > "Brian McCauley" <nobull@mail.com> schreef in bericht
> > > news:u9vfkwg5aw.fsf@wcl-l.bham.ac.uk...
> > > > "luc" <anonymous@disneyland.com> writes:
> > > >
> > > > > Is there a site somewhere where I can put my own perl scripts?
> > > >
> > > > This would depend on what they do and why you want to put them on a
> > > > site.
> > >
> > > just an ordinary script that processes some form data.
> >
> >
> > Are you asking for a location to put your own CGI scripts for your own
> > personal use?  Or for a respository of Perl scripts where people can store
> > scripts they've written for others to download and use?
> >
> > Paul Lalli
>
> It would be a script to process a form for a site I made but I cant put it
> on my site's server so I thought maybe to put it somewhere else and then in
> my html code put a link to it.

So then you're looking for a free webhost.  This is no longer a topic for
this newsgroup (which is supposed to be about the Perl language...).  Your
best bet is Google, which turned up this site as one of the first results
for "free webhost CGI":
http://www.free-webhosts.com/

Paul Lalli


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

Date: Mon, 22 Mar 2004 12:02:46 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: selfmade scripts
Message-Id: <105ue29p1j293d1@corp.supernews.com>

luc wrote:

> It would be a script to process a form for a site I made but I cant put it
> on my site's server so I thought maybe to put it somewhere else and then in
> my html code put a link to it.

Try asking at alt.www.webmaster



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

Date: Mon, 22 Mar 2004 16:41:30 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: using a variable as STDIN for an external program
Message-Id: <61692841674bce57f21a8d007c2e0765@news.teranews.com>

>>>>> "C3" == C3  <gned@telsmonopolytradotcom.remove.monopoly)> writes:

C3> I'd like to call an external program through perl, but I need to redirect a
C3> variable in my perl program, to STDIN of the external program. I also need
C3> to read the output of the external program (one line only).

C3> Can someone please point me in the right direction? I've been googling for a
C3> while now, and I'm still not sure whether I can do a simple redirection
C3> (with interpolation) or whether I have to set up a pipe.

If you don't mind a double fork... (and the advantage here is that a
shell never gets involved, so you don't have any whitespace or
shell-quoting dependencies):

    my $input = "This is a test of the\nEMERGENCY BROADCASTING SYSTEM!\n";
    my $result; # where the answer goes

    if (open RESULT, "-|") { # original process
      local $/;
      $result = <RESULT>;
    } else { # child
      if (open STDIN, "-|") { # child
        exec "tr","a-zA-Z", "A-Za-z";  # your child goes here
        die "Cannot exec: $!";
      } else { # grandchild
        print $input;
        exit 0;
      }
    }

    print "$result";

And that prints:

    tHIS IS A TEST OF THE
    emergency broadcasting system!

print "Just another Perl hacker,"
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

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


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