[15844] in Perl-Users-Digest
Perl-Users Digest, Issue: 3258 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 5 18:10:55 2000
Date: Mon, 5 Jun 2000 15:10:24 -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: <960243023-v9-i3258@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 5 Jun 2000 Volume: 9 Number: 3258
Today's topics:
Re: How to open a textfile from a library file <sean77@dds.nl>
Re: How to open a textfile from a library file (Bart Lateur)
Re: How to open a textfile from a library file <sean77@dds.nl>
IP/Port check <helza@planet.nl>
module for MsAccess database? <mr.soetjianto@mail.tju.edu>
Re: module for MsAccess database? <red_orc@my-deja.com>
Re: multiple foreach - logic question (Joe Smith)
Multiple Threads Running Perl via Shared Lib - Possible (Nick Knight)
New user: Accessing C APIs rpool@my-deja.com
Re: Newbie needs help with search and replace <red_orc@my-deja.com>
Re: Perl unusable as a programming language <Torsten.Hilbrich@gmx.net>
Re: Perl vs Python for Numerical Analysis (Craig Berry)
perlxstut x3matdeja@my-deja.com
Re: please help in checking the referer site and giving <lr@hpl.hp.com>
ppmfix install problems <vromeo@vanguardhc.com>
Re: Predicted generation of ID numbers <webmaster@beautiful-ladies.com>
problem with parsing data submitted through form!! prakash_ojha@my-deja.com
problem with parsing data!! prakash.ojha@hope.edu
Re: problem with regex <red_orc@my-deja.com>
Re: problem with regex <npecca@yahoo.com>
Re: problem with regex (Neil Kandalgaonkar)
Re: problem with regex (Bart Lateur)
Re: Still a little puzzled (Was Re: Globbing with Activ (Eric Bohlman)
Re: Still a little puzzled (Was Re: Globbing with Activ <bdelmee@dilys.be>
Re: time/date calculation <npecca@yahoo.com>
Re: time/date calculation <sb@muccpu1.muc.sdm.de>
Unable to parse argument from script A to script B. <kennylim@techie.com>
use DBI beer_girl@bigfoot.com
Re: using 'exists' in a program to test for keys in a h (Ala Qumsieh)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 5 Jun 2000 21:20:51 +0200
From: "Seansan" <sean77@dds.nl>
Subject: Re: How to open a textfile from a library file
Message-Id: <393bfda2$0$2789@reader5>
I tried %INC, but if its not there ??
and __FILE__ just returns the current filename.
I need something for the current directory.
------------------------------
Date: Mon, 05 Jun 2000 19:33:26 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How to open a textfile from a library file
Message-Id: <393d0013.561663@news.skynet.be>
Seansan wrote:
>I tried %INC, but if its not there ??
For a module Foo::Bar, look at the entry for "Foo/Bar.pm".
>and __FILE__ just returns the current filename.
>I need something for the current directory.
Heh, funny, it returns the full path for me. Just strip off the file's
basename, and bingo.
--
Bart.
------------------------------
Date: Mon, 5 Jun 2000 21:32:19 +0200
From: "Seansan" <sean77@dds.nl>
Subject: Re: How to open a textfile from a library file
Message-Id: <393c0a91$0$25656@reader2>
Found it out.
Thanks.
__FILE__
does contain the location, but only when I reference the library file from
main by using :
use 'file_location';
use filename;
------------------------------
Date: Sat, 3 Jun 2000 15:09:02 +0200
From: "Helza" <helza@planet.nl>
Subject: IP/Port check
Message-Id: <8hb05s$86426$1@reader1.wxs.nl>
Hi,
I really need some help here. I'm building a program which gets information
from Servers which are running. (cgi)
Which goes perfect as long as the server is up.
But as soon as a invalid IP/port is entered or the server is down the
program will load like crazy but nothing happens for a long time, until
after a long time it finally gives any form of error.
And because the program will have to load a number of ip's entered by
visitors and loads these i'm pretty sure always a couple of those ip's will
be offline :(
How do i make a quick ip/port check to see if the server is online?
Currently i use this code:
--------------------
#!/usr/bin/perl
use Socket;
$host = shift || "130.89.225.137";
$port = shift || 63881;
$request =
"\xE0\x69\x88\xCF\x10\x10\x14\x00\x00\xFC\x43\xE2\x35\x6B\xD1\x11\x87\x87\x0
0\xC0\xF0\x16\xAF\x25";
@Type = ( "COOPERATIVE","DEATHMATCH","TEAM DEATHMATCH","KING OF THE
HILL","TEAM KING OF THE HILL","CAPTURE THE FLAG","SEARCH AND DESTROY","ATACK
AND DEFEND","TEAM FLAGBALL" );
@Server = ( "Serve & Play", "Dedicated" );
$iaddr = inet_aton("0.0.0.0");
$proto = getprotobyname('udp');
$paddr = sockaddr_in(3568, $iaddr);
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
bind(SOCKET, $paddr) || die "bind: $!";
$| = 1;
$hisiaddr = inet_aton($host) || die "unknown host";
$hispaddr = sockaddr_in($port, $hisiaddr);
defined(send(SOCKET, $request, 0, $hispaddr)) || die "send $host: $!";
$rin = 0;
vec($rin, fileno(SOCKET), 1) = 1;
if( select($rout = $rin, undef, undef, 2) == 0 ) {
print "Content-type: text/html\n\n<font class=R>Server is down</font>\n";
exit;
}
($hispaddr = recv(SOCKET, $responce, 512, 0)) || die "recv: $!";
($type,$dedicated,@ver) = (unpack("C260",
$responce))[248,252,259,258,257,256];
( $mask, @data ) = unpack( "V C36", $responce );
for( $i=0; $i < 32; $i++ ) {
$data[$i] = $data[$i] & ~1 | $mask & 1;
$mask = $mask >> 1;
}
etcetc..and goes on here with the information it got from server :)
------------------------------
Date: Mon, 5 Jun 2000 16:26:05 -0400
From: "Soetjianto" <mr.soetjianto@mail.tju.edu>
Subject: module for MsAccess database?
Message-Id: <8hh2ii$5ic$1@omle.tju.edu>
Is there a PERL module for interfacing with MsAccess databases?
Thanks,
Soetji
------------------------------
Date: Mon, 05 Jun 2000 21:01:48 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: module for MsAccess database?
Message-Id: <8hh4ff$l5c$1@nnrp1.deja.com>
In article <8hh2ii$5ic$1@omle.tju.edu>,
"Soetjianto" <mr.soetjianto@mail.tju.edu> wrote:
> Is there a PERL module for interfacing with MsAccess databases?
>
Win32::ODBC ?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 05 Jun 2000 18:48:30 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: multiple foreach - logic question
Message-Id: <393bf5fe$0$2983@nntp1.ba.best.com>
In article <78R_4.4615$2b4.320195@bgtnsc06-news.ops.worldnet.att.net>,
Jeremiah Adams <adams1015@worldnet.att.net> wrote:
>Hi I've got this logic problem maybe someone can help me out with it.
>
>I need to take user submitted data and split it at white space. Then I need
>to search a flat file with each piece of the split data from the user. The
>problem is that I also need to split the flat file data at white space as
>well and look for mathes at each split. For example - the user data: ugly
>dog and the flat file data : nice dog
@words = qw(ugly dog);
%wanted = (); # Hash of things to look for
@wanted{@words} = @words; # Populate hash
while(<IN>) {
foreach $word (split) {
print if defined $wanted{$word};
}
}
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Mon, 05 Jun 2000 20:34:51 GMT
From: nick@secant.com (Nick Knight)
Subject: Multiple Threads Running Perl via Shared Lib - Possible? Safe?
Message-Id: <8F4AA36A6nicksecantcom@38.9.69.2>
Hello,
The basic question is, is Perl 5.6.0 thread safe? I have an application
where I want to wrap Perl up in a shared library (Linux, WinNT, BSDI and
maybe Solaris), then have my application be able to run scripts in a
multithreaded manner. IOW, my app wants to create multiple threads with
each thread capable of running a Perl script. It may be a bunch of
different scripts, or the same script with different parameters in each
thread.
Now, I tried to research this via dejanews, and what I found were mixed
signals. The closest I came to "an answer" was a post from 10/99 in which
I read:
>>I've tried to understand how I can use embedded perl in a multithread
>>application and I'm a bit confused.
>>We have a process in a multithread mode. This process is linked with an
>>embedded perl library. Each thread starts its own perl interpreter. Is
>>it safe to run several threads at the same time, where each thread is
>>executing separate interpreters ?
>
>This isn't safe. You must protect perl with a global mutex and make
>sure that only one thread is in any perl interpreter at any one
>time. This may be safe in 5.6 (and only if you build with
>threads) but it isn't now.
>
>And embedding a threaded perl isn't enough either, as perl
>takes a mnumber of shortcuts if it thinks there's only one
>thread running.
---
This tells me what I want to do may not be feasible. Except, "may be safe
in 5.6". Does anyone know for a fact? Has anyone done this?
Thanks in advance!
Nick
------------------------------
Date: Mon, 05 Jun 2000 20:02:22 GMT
From: rpool@my-deja.com
Subject: New user: Accessing C APIs
Message-Id: <8hh100$i6g$1@nnrp1.deja.com>
Hello everyone. I'm really in a bind because I'm really new to perl
and yet need to finish a fairly large program in a short timeframe. If
anyone out there can help me, I'd really appreciate it.
Background:
Currently we use a program called HP OpenView to act as the center of
our Enterprise Management activities. OpenView goes out and verifies
the up/down status of devices on our network by sending a ping to each
device. OpenView also receives SNMP traps from management enabled
devices such as our Cisco routers and our NT Servers. If a managed
device does not respond to it's ping, or if a router generates a trap
that says it's having troubles OpenView creates an 'event'
corresponding to the particulars of what's wrong. For example two
common events are "Server X is down" or "Interface X on Router Y has
lost signal".
When OpenView creates an event it can execute an optional command line
or alert other programs via it's API. Right now when an event we are
interested in is created OpenView runs a command line to have another
program called Telalert send out a notification of that event. Usually
notification is via an on call pager. The problem is, we are getting
an excessive number of notifications about router interfaces going down
and back up. These don't really concern us if they are short, they
just annoy us in the middle of the night (last night I got 200 pages,
most of them could have been ignored).
The proposed solution:
I have been asked to write a perl script to interface with OpenView's
API, which is a C API, so that specific events will be given to the
script to handle. The script then needs to look at the event and
determine if it is an up or down event and what the source is. If the
event is a down event the script should hold on to that event for a
predetermined amount of time to wait for an up event from the same
source. If the up event doesn't come in then the script should send
out a notification through a Telalert command. If an up event does
come in then we don't want to send a notification.
As an added complexity we also need to track the number of times and
when a device goes down. If it goes down more than X times in Y time
interval we want to send a page from Telalert. As another complexity
there could be multiple down messages come in at the same time that
would all need to be tracked simultaneously.
My first concern is that don't know how to access the OpenView API from
perl. I'm looking at the perlxstut manpage and going through that so
hopefully I can figure it out. Is that the best way to go? I'm sorry
I don't even know the right questions to ask yet.
Thanks,
Ryan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 05 Jun 2000 18:26:22 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Newbie needs help with search and replace
Message-Id: <8hgrbo$dkl$1@nnrp1.deja.com>
In article <393BDB38.6FB73DB0@stomp.stomp.tokyo>,
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Neil Watson wrote:
>
> > I have a file that has lines similar to
> > (each line is spaced the same):
>
> > PSteel8804 A 10000000000000000A0
>
> (snipped)
>
> > P128814S A 10000000000000000A0
>
<SNIP>
> foreach $element (@String)
> {
> if ($element =~ /PSteel/)
> {
> $element = substr ($element, 0, 35);
> $element = join ("", $element, "0S0");
if using substr anyway, could use:
# tested under perl 5.00503 only . . .
substr($element, length($element)-3, 3, '0S0');
> }
> print "$element\n";
> }
>
> exit;
>
<SNIP>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 02 Jun 2000 21:19:47 +0200
From: Torsten Hilbrich <Torsten.Hilbrich@gmx.net>
Subject: Re: Perl unusable as a programming language
Message-Id: <87snuvyjos.fsf@myrkr.in-berlin.de>
Dan Sugalski <dan@tuatha.sidhe.org> writes:
[$1 is BLOCK scoped]
> > That might be either a bug or a misunderstanding on my part.
>
> Misunderstanding. Which is understandable, since it's both kinda odd and
> undocumented.
man perlre yields:
upon. See the WARNING below.) The scope of $<digit> (and
$', $&, and $') extends to the end of the enclosing BLOCK
or eval string, or to the next successful pattern match,
whichever comes first. If you want to use parentheses to
At least it is not totally undocumented.
Torsten
--
Homepage: http://www.in-berlin.de/User/myrkr
------------------------------
Date: Mon, 05 Jun 2000 19:52:33 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl vs Python for Numerical Analysis
Message-Id: <sjo181q85ri183@corp.supernews.com>
: > Convincing Python advocates that Perl is anything beyond the spawn
: > of Satin is typically a lost cause...they typically just won't
: > listen. :-(
Spawn of Satin? Absurd! More of a raw silk sort of language, I'd say.
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "You live in Los Angeles, and you are going to Reseda; we are
| all in some way or another going to Reseda someday, to die."
- Soul Coughing
------------------------------
Date: Mon, 05 Jun 2000 21:09:27 GMT
From: x3matdeja@my-deja.com
Subject: perlxstut
Message-Id: <8hh4to$lhu$1@nnrp1.deja.com>
Hi!
Trying to learn how to extend perl with own c-code. I followed the
example in perlxstut (trying to create a perl-module that writes "hello
world"), but though everything looks ok I get the following message
when I try to access my module (Mytest)
Can't find symbol boot_Mytest symbol in .... Mytest.so
I'm using perl5.00503 under linux RH6.2 .... I've followed the example
in
the perlxstut strictly.. anyone got a clue ?
regards
/bengt
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 5 Jun 2000 13:46:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: please help in checking the referer site and giving page view authorisation
Message-Id: <MPG.13a5b17e18c395b898ab22@nntp.hpl.hp.com>
In article <393A3EA5.E42430A1@worldonline.nl> on Sun, 04 Jun 2000
13:33:57 +0200, Vincent Voois <vvacme@worldonline.nl> says...
> Sorry i made one typo:
> > if (@refs[2] eq 'www.hitostat.com' || @refs[3] eq '64.65.31.50'){
>
> should be
> if (@refs[2] eq 'www.hitostat.com' || @refs[2] eq '64.65.31.50'){
There is more than just a typo there. You are comparing an array slice
against a scalar (twice), and the '-w' flag would warn you about that.
For your own sake, you should start to use it (and 'use strict;', though
that is a different matter).
Array elements are scalars, so should be indicated as such:
... $refs[2] ... (twice)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 5 Jun 2000 14:59:31 -0500
From: "Vince Romeo" <vromeo@vanguardhc.com>
Subject: ppmfix install problems
Message-Id: <dET_4.175711$VR.2791763@news5.giganews.com>
Total newbie, attempting to install Activeperl 613 on NT 4.0sp6a, followed
by ppmfix hotfix. When I run the provided ppmfix.bat or type ppm
verify --upgrade --location=. PPM I get the following message: Error
verifying PPM: Package 'PPM' has not been installed by PPM
Help? Suggestions?
-Vince
------------------------------
Date: Mon, 05 Jun 2000 21:46:48 GMT
From: Andrej <webmaster@beautiful-ladies.com>
Subject: Re: Predicted generation of ID numbers
Message-Id: <8hh742$nb2$1@nnrp1.deja.com>
In article <8hfjh0$rb4$1@orpheus.gellyfish.com>,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Sun, 04 Jun 2000 07:10:28 GMT Andrej wrote:
> > Other question, is the similar scheme of auto definition UNIX/WIN
> > efficient here?
> >
> > if (-s "/bin/ln" ) {
>
> I would probably use $^O instead - as this is far more certain to be
accurate.
>
> There is always the outside chance that there will be a /bin/ln on
some
> windows machine you encounter.
>
It is my machine, /bin/ln does not exist.. It is necessary only for my
experiments. Whether there are other reasons?
Thank you,
Andrej
http://www.beautiful-ladies.com/
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 05 Jun 2000 18:10:28 GMT
From: prakash_ojha@my-deja.com
Subject: problem with parsing data submitted through form!!
Message-Id: <8hgqe3$cpg$1@nnrp1.deja.com>
I tried following code to parse data submitted through form, but it
doesn't work.doesn't give errrors but doesn't do anygood either. can
anybody point out what's the problem???
&parse_form_data (*form);
foreach $key (keys %form){
print " $key $form{$key}";
}
sub parse_form_data
{
local (*FORM_DATA) = @_;
local($query_string, @key_value_pairs, $key_value, $key, $value);
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
if($ENV{'QUERY_STRING'}){
$query_string = join("&", $query_string, $ENV{'QUERY_STRING'})
}
@key_value_pairs = split(/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split(/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
if (defined($FORM_DATA{$key})){
$FORM_DATA{$key} = join("\0", $FORM_DATA{$key}, $value);
}else {
$FORM_DATA{$key} = $value;
}
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 05 Jun 2000 19:41:14 GMT
From: prakash.ojha@hope.edu
Subject: problem with parsing data!!
Message-Id: <8hgvom$h68$1@nnrp1.deja.com>
I tried following code to parse data submitted through a form, but it
doesn't work.doesn't give errrors but doesn't do
anygood either. can anybody point out what's the problem???
&parse_form_data (*form);
foreach $key (keys %form){
print " $key $form{$key}";
}
sub parse_form_data
{
local (*FORM_DATA) = @_;
local($query_string, @key_value_pairs, $key_value, $key, $value);
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
if($ENV{'QUERY_STRING'}){
$query_string = join("&", $query_string, $ENV{'QUERY_STRING'}) }
@key_value_pairs = split(/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split(/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
if (defined($FORM_DATA{$key})){
$FORM_DATA{$key} = join("\0", $FORM_DATA{$key}, $value); }else {
$FORM_DATA{$key} = $value;
}
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 05 Jun 2000 18:07:58 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: problem with regex
Message-Id: <8hgq9e$cmi$1@nnrp1.deja.com>
In article <8hgngj$aap$1@nnrp1.deja.com>,
frankgroch@my-deja.com wrote:
> hello!
>
> i'm searching for a regex, which replaces lines in a file between two
> given keys.
>
> i can find what i'm searching for with:
>
> 'print if /key1/ ... /key2/;'
>
> but i don't know, how to replace it.
>
#!/usr/local/bin/perl -w
use strict;
my $one = 'key1 key2';
$one =~ s/key1/gork/ ;
print "$one\n";
=============
perldoc perlre
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 5 Jun 2000 22:24:29 +0400
From: "HB" <npecca@yahoo.com>
Subject: Re: problem with regex
Message-Id: <393bf2c1@news.telekom.ru>
s/PATTERN/REPLACEMENT/egimosx
Sorry if I misunderstood what your problen was.
------------------------------
Date: 5 Jun 2000 19:37:26 GMT
From: nj_kanda@alcor.concordia.ca (Neil Kandalgaonkar)
Subject: Re: problem with regex
Message-Id: <8hgvhm$i6c$1@newsflash.concordia.ca>
In article <8hgngj$aap$1@nnrp1.deja.com>, <frankgroch@my-deja.com> wrote:
>hello!
>
>i'm searching for a regex, which replaces lines in a file between two
>given keys.
>
>i can find what i'm searching for with:
>
>'print if /key1/ ... /key2/;'
>
>but i don't know, how to replace it.
In a one-liner:
perl -pi.bak -e 's/this/that/ if /begin/../end/' myfile.txt
or, if your replacement isn't regex-based:
perl -pi.bak -e 'if (/begin/../end/) { $_ = "replace with this" }'
See man perlrun for what the -p and -i switches do.
If you do not want to do this in a one-liner, you can use the explanations
in man perlrun to write something similar yourself in explicit perl code.
--
Neil Kandalgaonkar
neil@brevity.org
------------------------------
Date: Mon, 05 Jun 2000 19:35:29 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: problem with regex
Message-Id: <393e00cd.747309@news.skynet.be>
frankgroch@my-deja.com wrote:
>i'm searching for a regex, which replaces lines in a file between two
>given keys.
>
>i can find what i'm searching for with:
>
>'print if /key1/ ... /key2/;'
>
>but i don't know, how to replace it.
>
>could anybody offer some help?
if (/key1/ ... /key2/) {
$_ = "Censored!\n";
}
HTH,
Bart.
------------------------------
Date: 5 Jun 2000 18:09:19 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Still a little puzzled (Was Re: Globbing with ActivePerl)
Message-Id: <8hgqcf$lm2$2@slb1.atl.mindspring.net>
jason (elephant@squirrelgroup.com) wrote:
: see the problem is that the shell is not doing any globbing at all ..
: the most likely reason is that ActivePerl is not passing the command
: line argument to the shell for processing prior to dealing with it
: itself
No, the problem is that the Win32 shells don't do *any* globbing (except
for arguments to shell built-ins like dir). Win32 console programs are
expected to do their own globbing. The 5.003 builds of ActivePerl
provided built-in "pre-globbing" but this is no longer automatic in later
versions. ActiveStates documentation describes a way to re-enable this
behavior.
------------------------------
Date: Mon, 5 Jun 2000 23:37:18 +0200
From: "Bernard Delmée" <bdelmee@dilys.be>
Subject: Re: Still a little puzzled (Was Re: Globbing with ActivePerl)
Message-Id: <8hh6jn$ags$1@news1.skynet.be>
"Eric Bohlman" <ebohlman@netcom.com> wrote:
> ActiveStates documentation describes a way to re-enable this behavior.
Nice to know. And would you be so kind to share the trick?
"perlglob.exe" used to get silently invoked with previous AP
builds. This program is still bundled, but seems indeed
disabled by default in the latest releases. Which is not
my idea of backward compatibility by any means!
------------------------------
Date: Mon, 5 Jun 2000 22:18:22 +0400
From: "HB" <npecca@yahoo.com>
Subject: Re: time/date calculation
Message-Id: <393bf152@news.telekom.ru>
carex wrote...
> I have to add 2 min to a date/time value
> eg. 06/30/2000 23h58 + 2min = 07/01/2000 00h00 and so on.
> Which perl module is the best suited for this task ?
I suppose Date::Calc is. It contains e. g. these functions:
Delta_Days
($year,$month,$day) = Add_Delta_Days($year,$month,$day,$Dd);
Add_Delta_DHMS
($year,$month,$day, $hour,$min,$sec) =
Add_Delta_DHMS($year,$month,$day, $hour,$min,$sec,$Dd,$Dh,$Dm,$Ds);
Add_Delta_YMD
($year,$month,$day) = Add_Delta_YMD($year,$month,$day,$Dy,$Dm,$Dd);
------------------------------
Date: 5 Jun 2000 18:25:13 GMT
From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
Subject: Re: time/date calculation
Message-Id: <8hgra9$an5$1@solti3.sdm.de>
In article <393BE8A7.FFB5CA9B@skynet.be>, carex <bachelart.pierre@skynet.be> wrote:
> I have to add 2 min to a date/time value
> eg. 06/03/2000 23h56 + 2min = 06/03/2000 23h58
> 06/03/2000 23h58 + 2min = 06/04/2000 00h00
> 06/30/2000 23h58 + 2min = 07/01/2000 00h00
> and so on.
> Which perl module is the best suited for this task ?
You might want to take a look at Date::Calc at
http://www.perl.com/CPAN/modules/by-module/Date/Date-Calc-4.3.tar.gz
There are probably also solutions involving the built-in function
"localtime()" (see "man perlfunc"), but people in this newsgroup
tend to disagree whether these solutions do or do not handle
daylight savings time and/or leap seconds correctly. ;-)
Maybe you should ask Larry Rosler about the correct answer, he
seems to know. :-)
Note that there are other Date modules around (e.g. like Date::Manip)
which might suit you also. Have a look!
Good luck,
--
Steffen Beyer <sb@engelschall.com>
http://www.engelschall.com/u/sb/whoami/ (Who am I)
http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)
------------------------------
Date: Mon, 5 Jun 2000 12:15:34 -0700
From: "Kenny Lim" <kennylim@techie.com>
Subject: Unable to parse argument from script A to script B.
Message-Id: <NZS_4.32451$5k2.53790@dfw-read.news.verio.net>
Hi All,
I am just a beginner and my objective here is to be able to "spun multiple
user session" to perform "specified amount" of rows to be inserted into the
table to generate
contentions for testing puposes.
So far, I am able to spun multiple sessions and perform number of rows to be
inserted into a table
only when I perform the following task:
(a) Hardcoded on the number of rows to be inserted into the table in script
B.
ie. my $number_rows = 1000;
(b) Manually predeclare to the value in the environment.
ie. my $number_rows = $ENV{"number_rows"}; # So far I have to predeclare
the value in the environment manually first.
#I would like to make the process a little more intuitive so that the user
can
just specified the following parameters to connect to the database via dbi
and perform the automation task easily based on the Script A.
#Connect_String
#Username
#Password
#Session_amount
#number_of_rows.
So far, I am unable to parse the argument to the second scripts and would
probably
have to set the argument in the environment level to get it to work.
Question :
(a) Do you by anychance have a better suggestion/Sample as to how I can
parse the
argument from script A to script B. (NT environment).
(b) If not, do you know how to create the environment on each shell that had
been invoked via the
Script A ? (I tried system (..) and so far it does not register the
environment, further this would
have to be set on each shell that have to be invoked)
#My guess is that I am just probably missing something which causes me to
unable
to parse the argument to the second scripts.
Please let me know if you need more explicit information.
Any advise would be appreciated, Thanks All in advance.
Kenny-
# Non working sample on script for A and B when I am
attempting to work on the environmental method settings.
#===Script A====#
# t.pl
# try to launch n simultaneous RunAllSql.pl sessions.
# usage perl t.pl -n4
# (if you don't specify -n, then 1 is assumed).
use Win32::Process;
use DBI;
# ==========================================================
# process command line
# ==========================================================
# ie -S server -U user -P Password -n4
use Getopt::Std;
getopts( 'S:U:P:n:v:' ); # ie -S server -U user -P Password -n4
print "\n\n\n #----- Perl Session Spinner -----#\n\n\n";
print "Enter Connect String: ";
$connect_string = <STDIN>;
chomp $connect_string;
print "Enter User Name: ";
$user_name = <STDIN>;
chomp $user_name;
print "Enter Password: ";
$password = <STDIN>;
chomp $password;
print "Enter Session Amount: ";
$session_amount = <STDIN>;
chomp $session_amount;
print "Enter Number of Rows: ";
$number_rows = <STDIN>;
chomp $number_rows;
#print "\n\n\nInitializing Automation Session.......\n\n";
#nsessions
$opt_n = $session_amount; #specify the number of users to run the job
simultenously
# ==========================================================
#pick up a default datastring from the environment.
#if unspecified use empty string (local server).
# ==========================================================
$dbh = DBI->connect ("dbi:Oracle:$connect_string", "$user_name","$password",
{
PrintError => 0,
RaiseError =>1
} );
# ==========================================================
# find where cmd.exe lives.
# ==========================================================
my $Cmd = `which cmd`;
#switch all forward slash to backslash.
$Cmd =~ s#/#\\#g;
#all back to forward
#$Cmd =~ s#\\#/#g;
#double all backslashes.
$Cmd =~ s#\\#\\\\#g;
# ==========================================================
# run n simultaneous(?) processes
# ==========================================================
my $i;
my $v;
for ( $i = 0; $i < $opt_n; ++$i )
{
RunProcess();
}
# ========================================================================
sub RunProcess
{
my $ProcessObj;
#print "Cmd = $Cmd\n";
chomp($Cmd);
#cheesy way to simulate a fork in NT.
# note: the programatic way to get the cmd.exe path doesn't work. (?)
Win32::Process::Create($ProcessObj,
$Cmd,
cmd /c perl RunAllSql2.pl -S$connect_string -U$user_name -P$password",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
#$ProcessObj->Suspend();
#$ProcessObj->Resume();
#$ProcessObj->Wait(INFINITE);
}
# ========================================================================
sub ErrorReport
{
print Win32::FormatMessage( Win32::GetLastError() );
}
#====Script B=====#
#!/usr/bin/perl
# RunAllSql.pl - Runs all .sql files in current directory.
# usage:
# perl RunAllSql.pl -U user -P password -S server -n NumSessions
# (defaults to sys/sys@$ORACLE_SERVER ).
# NumSessions defaults to 0 - ie don't fork.
# otherwise n processes are forked. ( Unix only ).
# the NT version uses Win32::Spawn
#
# suggest using somewhere between 30 and 100 processes per
# machine (simulates 30 to 100 users per box).
# bgw.
use Win32::Process;
use DBI;
use Getopt::Std;
getopts( 'S:U:P:n:v:' ); # ie -S server -U user -P Password
#$Data_source = $ENV{"ORACLE_SERVER"} if ( !$opt_S );
my $connect_string = $ENV{"connect_string"}; #===>Have to predeclared
first in able to get it to work!
my $user_name = $ENV{"user_name"};
my $password = $ENV{"password"} ;
my $number_rows = $ENV{"number_rows"};
# ==========================================================
#pick up a default datastring from the environment.
#if unspecified use empty string (local server).
# ==========================================================
# To make sure that the valus is correct.
print "$connect_string";
print "$user_name";
print "$password";
my $dbh = DBI->connect(
"dbi:Oracle:$connect_string", $user_name, $password )
|| die "Can't connect to $Data_source: $DBI::errstr";
#========================================================================
my $insert = ("insert into loop values (loopseq.NEXTVAL, 'a','b','c','d')");
my $i;
for ( $i = 0; $i < $number_rows; ++$i )
{
my $sth = $dbh->do("$insert")
or die "Couldn't prepare statement: " . $dbh->errstr;
};
$dbh->disconnect;
print "\n\n\nSession Completed..\n\n\n";
------------------------------
Date: Mon, 05 Jun 2000 21:49:14 GMT
From: beer_girl@bigfoot.com
Subject: use DBI
Message-Id: <8hh78j$ncd$1@nnrp1.deja.com>
I wrote a perl script that accesses mySQL and the script is executed
through a web browser (and it works great). Now I need to run it from
the command line and I get all kinds of syntax errors. Some of them
are:
here's the code:
use DBI;
($db) = DBI->connect('DBI:mysql:DatabaseName, $dbusername);
here's the corresponding errors:
syntax error in file ParseEmail.cgi at line 66, next 2 tokens "use DBI"
syntax error in file ParseEmail.cgi at line 82, next 2 tokens "->"
All this works just great if it's run through a web browser. What's
going on?!?
It's running on FreeBSD using Perl5
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 05 Jun 2000 18:14:41 GMT
From: aqumsieh@hyperchip.com (Ala Qumsieh)
Subject: Re: using 'exists' in a program to test for keys in a hash
Message-Id: <8F4A98F12aqumsiehhyperchipcom@198.235.216.4>
rgw303@mailandnews.com (RGW303) wrote in
<2Fg_4.2890$Fe.87116@newsread2.prod.itd.earthlink.net>:
>Ok, I copied and pasted the Perl program the uses DB and compiled
>and I get the same error. I get the error that DB_File module could
>be found in @INC (c:\perl\lib) and low and behold it's not there.
>I've repaired and reinstalled ActivePerl Build 613 several times.
>I've even uninstalled it and reinstalled it but it won't show up.
>However, I do have the file SDBM_File.pm in C:\perl\lib and when I
>use that program example that you posted here (copied and pasted
>exactly as shown). I still the error: "SDBM_File doesn't define an
>EXISTS method at myprog.pl line xx". (I made sure exists was
>lowercase). If it makes any difference, I'm running Windows 98 SE.
I have never used DB_File or SDBMK_File before, but the error you're
getting is due to a missing EXISTS method in your SDBM_File module :-)
I am assuming that you tie a hash variable to your DB using a command
similar to:
tie %hash, 'SDBM_File', qw/bla bla/;
This effectively says that the way you access %hash is governed by
functions defined in SDBM_File.pm. Specifically, in your case, if you
try to use exists() on a hash entry, Perl will go and find the EXISTS
method in SDBM_File and execute it, instead of executing the built-in
exists() function. Apparently, this method is missing for some reason.
For more info, checkout 'perltie'.
--Ala
------------------------------
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 3258
**************************************