[15907] in Perl-Users-Digest
Perl-Users Digest, Issue: 3320 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 11 09:10:23 2000
Date: Sun, 11 Jun 2000 06:10:15 -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: <960729014-v9-i3320@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 11 Jun 2000 Volume: 9 Number: 3320
Today's topics:
Re: now this is strange... <raphaelp@nr1webresource.com>
Re: now this is strange... <raphaelp@nr1webresource.com>
Re: now this is strange... <abuse@localhost>
Re: please help <gellyfish@gellyfish.com>
Re: Premature end of script headers? <gellyfish@gellyfish.com>
Re: rmdir in NT 4... (jason)
Re: Shebang line -- What exactly does Perl do? (Bart Lateur)
Re: Shebang line -- What exactly does Perl do? <you.will.always.find.him.in.the.kitchen@parties>
Re: Shebang line -- What exactly does Perl do? <gellyfish@gellyfish.com>
Re: Shebang line -- What exactly does Perl do? <flavell@mail.cern.ch>
Re: site_perl vs lib <nospam@nospam.com>
Re: Time-Date Question ?? <lr@hpl.hp.com>
Re: Time-Date Question ?? <gellyfish@gellyfish.com>
Trying to figure out how wtmp is packed <imaginos@imaginos.net>
Re: Trying to figure out how wtmp is packed (Joe Broz)
Re: uses for PERL (Bart Lateur)
Re: Using perl's modules DBD:Mysql and DBI and mysql <gellyfish@gellyfish.com>
Re: Using perl's modules DBD:Mysql and DBI and mysql <gellyfish@gellyfish.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 11 Jun 2000 10:45:50 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: now this is strange...
Message-Id: <8hvjig$10r$1@news.online.de>
nope, didn't use any modules. Well, I guess I'll just use the whole variable
definition "sheet". After all, it doesn't matter really. I just wanted to
make the script a little shorter... :-)
jason <elephant@squirrelgroup.com> wrote in message
news:MPG.13ad6536a328055e98971e@news...
> Raphael Pirker writes ..
> >I have quite a few variables that need to be defined:
> >
> >$autoresp_state = $FORM{autoresp_state};
> >$autoresp_from = $FORM{autoresp_from};
> >$autoresp_spam = $FORM{autoresp_spam};
> >$admin_state = $FORM{admin_state};
> >$admin_from = $FORM{admin_from};
> >$admin_sort = $FORM{admin_sort};
> >$results_message = $FORM{results_message};
> >$results_template = $FORM{results_template};
> >$results_cartoon = $FORM{results_cartoon};
> >$results_results = $FORM{results_results};
> >$results_link_text = $FORM{results_link_text};
> >$results_link_url = $FORM{results_link_url};
>
> if you used the CGI module instead of whatever is creating this %FORM
> hash (is it cgi_lib ?) then you could use the import_names() function
> which imports all the CGI form variables into a given namespace
>
> use CGI 'import_names'; import_names('Q');
>
> $Q::autoresp_state; #etc
>
> 'Q' is the default namespace btw .. BUT .. all those variables that
> you've got listed on the right above are scalars as well and can be used
> anywhere (god it makes me nervous using absolutes in here :) that a
> normal scalar can be used
>
> Disclaimer: where I say 'anywhere' above I really am only thinking about
> interpolation situations such as double-quoted strings and regexes ..
> although I can't think of any situation where they behave differently -
> there may be
>
> >Could anyone point me into the right direction? (please feel free to
> >underestimate my IQ... :-)
>
> something that a lot more posters here should invite .. well said
>
> what you're missing is called a symbolic reference .. but 'use strict'
> will not let you use it anyway .. and hashes are a far better
> alternative .. as is the CGI::import_names() function
>
> --
> jason - elephant@squirrelgroup.com -
------------------------------
Date: Sun, 11 Jun 2000 10:47:53 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: now this is strange...
Message-Id: <8hvjmb$127$1@news.online.de>
> I think you wanted $key as used in the for loop to magically be treated
> as $autoresp_state, etc.
Correct...
> Perl can't know you want to do this. If $x = "foo",
> $x has no relationship with $foo.
oops... :-)
> There *are* ways to do what you wanted but they are usually very very bad
> ideas.
Ok... I think I'll stay with what I had in the first place! Thanks!
Neil Kandalgaonkar <nj_kanda@alcor.concordia.ca> wrote in message
news:8hudn5$gb6$1@newsflash.concordia.ca...
> In article <8hu0if$iqv$1@news.online.de>,
> Raphael Pirker <raphaelp@nr1webresource.com> wrote:
>
> >I have quite a few variables that need to be defined:
> >
> >$autoresp_state = $FORM{autoresp_state};
> >$autoresp_from = $FORM{autoresp_from};
> >$autoresp_spam = $FORM{autoresp_spam};
>
> [...]
>
> >Now, what I want is to shorten this. I came up with an Idea, but this
$h!t
> >just doesn't want to work... :-)
> >
> >foreach $key (keys(%FORM)) {
> >$key = $FORM{$key};
> >}
> >
> >I'm more than stranded here. It took me ages to find a possible solution
and
> >now it doesn't work! :-(
>
> I think you wanted $key as used in the for loop to magically be treated
> as $autoresp_state, etc. Perl can't know you want to do this. If $x =
"foo",
> $x has no relationship with $foo.
>
> Anyway, there is nothing wrong with $FORM{'autoresp_state'}, you can use
it
> almost anywhere you would use $autoresp_state.
>
> There *are* ways to do what you wanted but they are usually very very bad
> ideas.
>
> See <http://www.plover.com/~mjd/perl/varvarname.html>.
>
> --
> Neil Kandalgaonkar
> neil@brevity.org
------------------------------
Date: Sun, 11 Jun 2000 19:36:36 +0800
From: "multiplexor" <abuse@localhost>
Subject: Re: now this is strange...
Message-Id: <8hvt5s$2f36@imsp212.netvigator.com>
"Raphael Pirker" <raphaelp@nr1webresource.com> wrote
> > I think you wanted $key as used in the for loop to magically be treated
> > as $autoresp_state, etc.
> Correct...
>
> > Perl can't know you want to do this. If $x = "foo",
> > $x has no relationship with $foo.
> oops... :-)
>
> > There *are* ways to do what you wanted but they are usually very very
bad
> > ideas.
> Ok... I think I'll stay with what I had in the first place! Thanks!
>
>
> Neil Kandalgaonkar <nj_kanda@alcor.concordia.ca> wrote in message
> news:8hudn5$gb6$1@newsflash.concordia.ca...
> > In article <8hu0if$iqv$1@news.online.de>,
> > Raphael Pirker <raphaelp@nr1webresource.com> wrote:
> >
> > >I have quite a few variables that need to be defined:
> > >
> > >$autoresp_state = $FORM{autoresp_state};
> > >$autoresp_from = $FORM{autoresp_from};
> > >$autoresp_spam = $FORM{autoresp_spam};
> >
> > [...]
> >
> > >Now, what I want is to shorten this. I came up with an Idea, but this
> $h!t
> > >just doesn't want to work... :-)
> > >
> > >foreach $key (keys(%FORM)) {
> > >$key = $FORM{$key};
> > >}
> > >
> > >I'm more than stranded here. It took me ages to find a possible
solution
> and
> > >now it doesn't work! :-(
> >
> > I think you wanted $key as used in the for loop to magically be treated
> > as $autoresp_state, etc. Perl can't know you want to do this. If $x =
> "foo",
> > $x has no relationship with $foo.
> >
> > Anyway, there is nothing wrong with $FORM{'autoresp_state'}, you can use
> it
> > almost anywhere you would use $autoresp_state.
> >
> > There *are* ways to do what you wanted but they are usually very very
bad
> > ideas.
> >
> > See <http://www.plover.com/~mjd/perl/varvarname.html>.
> >
> > --
> > Neil Kandalgaonkar
> > neil@brevity.org
I Don't know whether using "eval" is a bad idea.
Example:
###
%hash = (
a => '10',
b => '20'
);
print "a=$a ; b=$b\n";
foreach (keys %hash) {
$st = "\$$_ = \$hash{$_}";
print "$st\n";
eval $st;
}
print "a=$a ; b=$b\n";
###
I also use this code for convenience.
------------------------------
Date: 11 Jun 2000 12:19:14 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: please help
Message-Id: <8hvsji$npo$1@orpheus.gellyfish.com>
[de jeopardized]
On Sun, 11 Jun 2000 00:41:43 +0200 Helza wrote:
> Craig Berry <cberry@cinenet.net> wrote in message
> news:sk2es6v7h5120@corp.supernews.com...
>> Helza (helza@planet.nl) wrote:
>> : ohyeah part of code i forgot I tryed the Net::Ping
>> :
>> : ------
>> : #!/usr/bin/perl
>> :
>> : use Net::Ping;
>> :
>> : $host = "130.89.225.137";
>> : $p = Net::Ping->new();
>> : $retval = $p->ping($host,5);
>> : $p->close();
>> :
>> : print "Content-type: text/html\n\n";
>> : print "Retval value is: $retval";
>> : -------
>> : but everything i wrote below the $p->close();
>> : doesn't seem to be executed :(
>>
>> Just ran that very code here (perl 5.005, Solaris 2.6) and all was well
>> (returned 0, by the way).
>>
>
> Yes it returned 0, but as you'll see if you ping it, this server is up.
> so it should be returning a 1 :) not a 0
>
But if the server in question isnt running the TCP echo service than it
*will* appear to be down. Some ( most ?) systems administrators will
turn off this service. If you must use a TCP echo 'ping' rather than
a real ICMP ping then you will have to persuade the admin of the server
in question to enable the echo service.
Read the Net::Ping manpage to find out how to do ICMP ping ( of course
you will need to be have root permissions to do this on most systems).
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: 11 Jun 2000 12:24:34 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Premature end of script headers?
Message-Id: <8hvsti$nq5$1@orpheus.gellyfish.com>
On Thu, 08 Jun 2000 15:32:29 GMT Kevin Ferron wrote:
> I keep getting an error in my logs everytime I try to run a script.
>
> Jun 08 02:13:03 2000] [error] [client 127.0.0.1] Premature end of script
> headers: c:/inetpub/keen/cgi-bin/mailinglist/subscribe.pl
> [Thu Jun 08 02:13:03 2000] [error] [client 127.0.0.1] Died at
> c:/inetpub/keen/cgi-bin/mailinglist/subscribe.pl line 639.
>
> I'm running a win98 apache win32 with Activeperl with blatmail.
>
> I am unexperienced with Perl.
>
> This is line 639:
> Win32::Process::Create($ProcessObj, $mailprog, "Blat $tempfile\\tempfile -t
> $lines -s \"$INPUT{'mail_subject'}\" -i \"$list_mail ($list_name)\" -f
> \"$list_mail\" ", 0, DETACHED_PROCESS, ".")|| die $!;
>
> Could someone point me in the right direction? Thank you.
Read the appropriate Win32::* manpage to determine how to get the error
from the last Win32 API call as $! is not going to give you the
appropriate diagnostic message. In fact it is entirely possible that
Win32::Process::Create might not be susceptible for testing in this manner
at all.
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: Sun, 11 Jun 2000 07:18:14 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: rmdir in NT 4...
Message-Id: <MPG.13adda474ea86051989721@news>
Mark S. Blamey writes ..
>I've written this code and am finding the directory is not removed by
>rmdir. I'm assuming something is left in the directory so the command
>fails. How can I fix it so that the directory will be deleted as
>desired?
>
> opendir(FILES,"$my_dir/s$name");
> @filelist = grep(!/^\.|^_/, readdir (FILES));
> closedir(FILES);
> foreach $filelist (@filelist) {
> unlink("$my_dir/s$name/$filelist");
> }
> rmdir("$my_dir/s$name");
two things
a) you leave all files beginning either an underscrore or a period ..
obviously if there are either of these types of files in your directory
then you will not be able to delete it
b) you don't address any subdirectories or files within those
if the problem is not simply (a) then you will need a recursive function
that drills down and deletes all files .. then deletes the directories
if neither performance or portability are an issue - your easiest
solution would be using NTs 'RMDIR' command with the /S and /Q options
via a system() call
system('RMDIR /Q /S', "$my_dir\\s$name");
remember that you have to bow to the backwacked world of NTs directory
separator when using system() .. and those need to be escaped in double-
quoted strings
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Sun, 11 Jun 2000 08:47:49 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Shebang line -- What exactly does Perl do?
Message-Id: <39494dcd.5390119@news.skynet.be>
Tom Phoenix wrote:
>perl looks for the word "perl" on that line. If it's a shebang-line
>without that string, perl starts that program for you.
Eh? Perl starts a different program as referenced in the shebang line?
Is that normal behaviour?
I would think that the (Unix) shell would do that, and launch perl (or
another program) with the script as a parameter.
On a PC and on Mac, perl only looks for the "perl" magic word, and if
found, the switches are interpreted.
--
Bart.
------------------------------
Date: Sun, 11 Jun 2000 23:17:43 +1200
From: "Tintin" <you.will.always.find.him.in.the.kitchen@parties>
Subject: Re: Shebang line -- What exactly does Perl do?
Message-Id: <960722235.192341@shelley.paradise.net.nz>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:39494dcd.5390119@news.skynet.be...
> Tom Phoenix wrote:
>
> >perl looks for the word "perl" on that line. If it's a shebang-line
> >without that string, perl starts that program for you.
>
> Eh? Perl starts a different program as referenced in the shebang line?
> Is that normal behaviour?
I think what Tom meant was the the shebang line is read if you invoke a file
with perl, eg:
$ perl foo.pl
If the shebang line contains any of the valid Perl flags, then they will be
used.
------------------------------
Date: 11 Jun 2000 10:22:20 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Shebang line -- What exactly does Perl do?
Message-Id: <8hvloc$ng3$1@orpheus.gellyfish.com>
On Sat, 10 Jun 2000 16:11:24 -0700 Tom Phoenix wrote:
> On Sat, 10 Jun 2000, daniel mcgrath wrote:
>
>> So, what exactly happens with the shebang line?
>
> Is that what you needed, or is there something more?
>
Well there is the extra little bit of magic that if there is a shebang line
and that contains the path to another executable other than perl then Perl
will exec that interpreter with the program name as an argument, I've
never been quite sure of the utility of this feature but I'm sure someone
must use it.
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: Sun, 11 Jun 2000 13:57:11 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Shebang line -- What exactly does Perl do?
Message-Id: <Pine.GHP.4.21.0006111348480.29562-100000@hpplus03.cern.ch>
On Sun, 11 Jun 2000, Tintin wrote:
> I think what Tom meant was the the shebang line is read if you invoke a file
> with perl, eg:
>
> $ perl foo.pl
That's what I thought Tom was talking about, too.
> If the shebang line contains any of the valid Perl flags, then they will be
> used.
What I understood him to be saying was that if the file foo.pl were to
begin with, say,
#!/bin/sh
then perl would react to this by invoking /bin/sh for you.
boggle> more foo.pl
#!/bin/sh
echo foo
boggle> perl foo.pl
foo
boggle>
I _believe_ the point of this is if you were to configure Perl to be
your default shell, it allows you to invoke other shells by naming
them in the script rather than having to put them on the command line.
This is consistent with other shells, but whether there is any benefit
in configuring Perl to be one's default shell I'm not sure. Maybe in
Windoze?
I trust that Tom will be along any moment to correct any
misinterpretation of his intentions, however ;-)
------------------------------
Date: 11 Jun 2000 10:23:45 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: site_perl vs lib
Message-Id: <8hvpbh$pl3$0@216.155.32.169>
In article <3941f29e.495039@news.skynet.be>, bart.lateur@skynet.be
(Bart Lateur) wrote:
| The WebDragon wrote:
|
| > I
| >added the extra dir to my preferences and everything *seems* to be
| >working fine with the exception of Types.pm which keeps giving me
| >errors
| >at line 56 when I try and use the CPAN shell :(
| >
| >I haven't a CLUE what the error is from..
|
| Did you put the site_perl folder before the lib folder?
anything you add comes before the two defaults..
Interestingly, site_perl *is* there *as* a default, but only *after*
lib.. so it's there twice. *shrug*
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Sun, 11 Jun 2000 01:18:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Time-Date Question ??
Message-Id: <MPG.13aceb3bb05d4d4498ab5f@nntp.hpl.hp.com>
In article <Ooz05.12762$F9.398177@news1.gvcl1.bc.home.com>,
peter@PSDT.com says...
> In article <MPG.13ac164917ef974698ab5c@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> writes:
> >Golfers might prefer 'A2'x5 (saves four strokes :-).
> >
> >But the superiority of unpack over a set of substrs is quite clear.
>
> I assume you are talking about golf scores, not performance?
Those two, but more particlarly the need to manually calculate and
maintain the starting positions for each substr instead of letting the
unpack format do it for you.
...
> Benchmark: timing 1000000 iterations of regex, substr, unpack...
> regex: 44 wallclock secs (43.93 usr + 0.01 sys = 43.94 CPU) @ 22758.31/s (n=1000000)
> substr: 20 wallclock secs (19.76 usr + 0.00 sys = 19.76 CPU) @ 50607.29/s (n=1000000)
> unpack: 38 wallclock secs (37.53 usr + 0.00 sys = 37.53 CPU) @ 26645.35/s (n=1000000)
As for performance, substr is well know to be very fast. But I'm
surprised that unpack isn't faster than a set of substrs, as Uri Guttman
commented.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 11 Jun 2000 11:18:27 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Time-Date Question ??
Message-Id: <8hvp1j$nks$1@orpheus.gellyfish.com>
On Sat, 10 Jun 2000 22:35:26 GMT Peter J Scott wrote:
> In article <MPG.13ac164917ef974698ab5c@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> writes:
>>Golfers might prefer 'A2'x5 (saves four strokes :-).
>>
>>But the superiority of unpack over a set of substrs is quite clear.
>
> I assume you are talking about golf scores, not performance?
For myself I have little interest in golf scores, using unpack is probably
better for maintainer efficiency as there is only one point at which things
need to be changed if the format of the data is changed, using substr()
would mean that all the indexes need to be recalculated. Infact I find
it easier to frame a single unpack format than a bunch of substr()s.
Incidentally in my benchmark it seems that my explicit format is quicker
than Larry's calculated one by a gnat's nadger.
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: Sun, 11 Jun 2000 01:43:21 -0800
From: imaginos <imaginos@imaginos.net>
Subject: Trying to figure out how wtmp is packed
Message-Id: <sk6k15i6h51134@corp.supernews.com>
I'm trying to figure out how linux glibc wtmp is packed.
This is what i have so far, The variable $key is what i'm trying to figure out. I think i'm close
but i'm a ways off too. any thoughts ?
#!/usr/bin/perl
open (WTMP, "/var/log/wtmp");
$key = "L a12 a32 a256 l l";
$keylen = length(pack($key, ()));
while (sysread(WTMP, $buff, $keylen)) {
@blah = unpack($key, $buff);
foreach $val(@blah) {
print "'$val' ";
}
print "\n";
}
------------------------------
Date: Sun, 11 Jun 2000 10:46:46 GMT
From: jb@yperite.demon.co.uk (Joe Broz)
Subject: Re: Trying to figure out how wtmp is packed
Message-Id: <slrn8k6uo1.9i.jb@yperite.demon.co.uk>
On Sun, 11 Jun 2000 01:43:21 -0800, imaginos <imaginos@imaginos.net> wrote:
>I'm trying to figure out how linux glibc wtmp is packed.
>
>This is what i have so far, The variable $key is what i'm trying
to figure out. I think i'm close
>but i'm a ways off too. any thoughts ?
>
Look at man 5 utmp. The perl Cookbook has a bit of code that shows
how to do this as well.
------------------------------
Date: Sun, 11 Jun 2000 08:47:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: uses for PERL
Message-Id: <394645ec.3372559@news.skynet.be>
Jonathan Stowe wrote:
>Anyhow where do you want to start ? Bearing in mind that only 15 out
>the 234 example programmes I have made for this newsgroup in the last
>6 months have been anything to do with the CGI ...
It's a lot higher ratio with me. Except: Perl is an excellent generic
language in it's bare form, maybe one of the most generic languages ever
created. Most of my CGI scripts use universally applicable methods and
algorythms. "CGI" is just a wrapper, a way to get input into and output
from a script. Perl is good at it, too, but the CGI bit is roughly only
about 5% of the whole script.
--
Bart.
------------------------------
Date: 11 Jun 2000 11:49:33 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Using perl's modules DBD:Mysql and DBI and mysql
Message-Id: <8hvqrt$nn8$1@orpheus.gellyfish.com>
In comp.lang.perl.misc Jeff Zucker <jeff@vpservices.com> wrote:
> Sebastien THOMAS wrote:
>
>> $dbh_mysql=DBI->connect("dbi:mysql:news\@localhost","$user",$password);)
>
> Right, but the backslash is not needed and you do not turn on error
> checking.
>
The backslash *is* needed if the double quotes around the connect string
are not to be changed to single quotes :
In string, @localhost now must be written as \@localhost ....
Of course one doesnt even need to specify a server in this case as
'localhost' is the default.
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: 11 Jun 2000 11:43:47 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Using perl's modules DBD:Mysql and DBI and mysql
Message-Id: <8hvqh3$nmq$1@orpheus.gellyfish.com>
In comp.lang.perl.misc Sebastien THOMAS <Sebastien.THOMAS@none.net> wrote:
>
> Third problem is that nobody seems to do insert to an mysql databas from
> a perl script
>
Huh ? This is a program that has been run every day for more than a year
and it certainly *does* do an insert (I dont think it's got any company
confidential information in it but ignore it if it has :):
#!/usr/bin/perl -w
#*****************************************************************************
#* *
#* xxxxxxxxxxxxxxxxx *
#* *
#*****************************************************************************
#* *
#* PROGRAM : nas_summary.pl *
#* *
#* AUTHOR : JNS *
#* *
#* DESCRIPTION : Insert daily summary into DB data *
#* *
#* *
#*****************************************************************************
#* *
#* $Log: nas2.pl,v $
#* Revision 1.1 1999/04/13 11:19:05 xxxxx
#* Initial revision
#* *
#* *
#* *
#*****************************************************************************
use DBI;
my %daily_totals ;
my ( $indate, $intable ) = @ARGV;
my @months = qw(jan feb mar apr may jun jul aug sep oct nov dec);
my $yesterday = time - 86400; # Of course it wont work if run at the
# wrong time on the wrong day of the year
my ($sec,$min,$hour,$mday,$mon,$year) = localtime($yesterday);
my $strdate = $indate || sprintf("%d-%02d-%02d",$year + 1900, $mon + 1, $mday);
my $dbh = DBI->connect("DBI:mysql:radiusdb", '', '', '');
if ($dbh)
{
my $tabname = $intable || sprintf("%s%04d",$months[$mon],$year + 1900 );
my $sql_statement =<<EOQ;
SELECT date_time,
acct_session_time,
username,
ascend_presess_tim,
nas_identifier
FROM $tabname
where date_time LIKE "$strdate%"
EOQ
my $sth_query = $dbh->prepare($sql_statement);
if($sth_query->execute)
{
my @out_row = ();
while (@out_row = $sth_query->fetchrow)
{
$daily_totals{$out_row[4]}->[0]++;
$daily_totals{$out_row[4]}->[1] += $out_row[1];
$daily_totals{$out_row[4]}->[2] += $out_row[3] || 0 ;
}
my $ascend;
foreach $ascend ( keys %daily_totals )
{
my $insert_query =<<EOQ2;
INSERT INTO ascend_summary
VALUES ( "$strdate",
"$ascend",
$daily_totals{$ascend}->[0],
$daily_totals{$ascend}->[1],
$daily_totals{$ascend}->[2])
EOQ2
$sth_query = $dbh->prepare($insert_query)
|| warn "Couldnt insert for $ascend - $dbh->errstr\n";
$sth_query->execute;
}
}
else
{
die "Prepare failed - ",$dbh->errstr,"\n";
}
}
$dbh->disconnect;
Of course the program that populates the database tables from the raw data
will also be required to do an insert.
If programs didnt do an insert how does the data get into the database ?
(well OK you can do the loadfile thing ...)
/J\
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
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 3320
**************************************