[30381] in Perl-Users-Digest
Perl-Users Digest, Issue: 1624 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 9 16:14:23 2008
Date: Mon, 9 Jun 2008 13:14:16 -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 Mon, 9 Jun 2008 Volume: 11 Number: 1624
Today's topics:
select count in perl <avilella@gmail.com>
Re: select count in perl <bugbear@trim_papermule.co.uk_trim>
Re: select count in perl <dragnet\_@_/internalysis.com>
Re: select count in perl xhoster@gmail.com
Re: TCP apllications <tzz@lifelogs.com>
Re: Tk with Thread <zentara@highstream.net>
Re: Tk with Thread <slick.users@gmail.com>
use DBI <rodbass63@gmail.com>
Re: use DBI <danrumney@warpmail.net>
Re: use DBI <glex_no-spam@qwest-spam-no.invalid>
Re: use DBI <rodbass63@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 9 Jun 2008 07:56:19 -0700 (PDT)
From: "avilella@gmail.com" <avilella@gmail.com>
Subject: select count in perl
Message-Id: <01394da9-53af-4122-a3c9-7ba59cbbae80@r66g2000hsg.googlegroups.com>
Hi,
I would like to know how I could move the select count I am doing in
mysql on the perl side:
mysql -hhost -uanonymous mydb -e "select count(status), status from
table group by status order by null"
to instead something like:
mysql -hhost -uanonymous mydb -e "select status from table order by
null" | perl "give me the count numbers"
Anyone?
------------------------------
Date: Mon, 09 Jun 2008 16:00:10 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: select count in perl
Message-Id: <6umdnfd4d4vn2NDVnZ2dnUVZ8vidnZ2d@posted.plusnet>
avilella@gmail.com wrote:
> Hi,
>
> I would like to know how I could move the select count I am doing in
> mysql on the perl side:
>
> mysql -hhost -uanonymous mydb -e "select count(status), status from
> table group by status order by null"
>
> to instead something like:
>
> mysql -hhost -uanonymous mydb -e "select status from table order by
> null" | perl "give me the count numbers"
If the table is large that's a major "lose"
BugBear
------------------------------
Date: Mon, 09 Jun 2008 10:18:19 -0500
From: Marc Bissonnette <dragnet\_@_/internalysis.com>
Subject: Re: select count in perl
Message-Id: <Xns9AB872FE2B930dragnetinternalysisc@216.196.97.131>
"avilella@gmail.com" <avilella@gmail.com> fell face-first on the
keyboard. This was the result: news:01394da9-53af-4122-a3c9-7ba59cbbae80
@r66g2000hsg.googlegroups.com:
> Hi,
>
> I would like to know how I could move the select count I am doing in
> mysql on the perl side:
>
> mysql -hhost -uanonymous mydb -e "select count(status), status from
> table group by status order by null"
>
> to instead something like:
>
> mysql -hhost -uanonymous mydb -e "select status from table order by
> null" | perl "give me the count numbers"
>
> Anyone?
#!/usr/bin/perl
use CGI;
use URI::Escape;
$q = new CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
Define();
$query = "SELECT count(status) as totals, `status` FROM `table` GROUP BY
`status` ORDER BY null";
print "Status:\tTotals\n------------------\n\n";
my $dbh;
my $sth;
$dbh = DBI->connect("DBI:mysql:$dbname", $dbuser, $dbpass,{PrintError =>
1, RaiseError => 1});
$sth=$dbh->prepare($query);
$sth->execute();
$names = $sth->{NAME};
while (@row=$sth->fetchrow()) {
$count=0;
for (@row) {
$fieldname=@$names[$count];
$data{$fieldname}=$row[$count];
$data{$fieldname}=uri_unescape($data{$fieldname});
++$count;
}
print "$data{status}\t$data{totals}\n
}
$sth->finish;
$dbh->disconnect;
exit;
sub Define {
$dbname='databasename';
$dbuser='databaseuser';
$dbpass='databasepassword';
}
--
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.
------------------------------
Date: 09 Jun 2008 16:34:27 GMT
From: xhoster@gmail.com
Subject: Re: select count in perl
Message-Id: <20080609123428.807$gF@newsreader.com>
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> avilella@gmail.com wrote:
> > Hi,
> >
> > I would like to know how I could move the select count I am doing in
> > mysql on the perl side:
> >
> > mysql -hhost -uanonymous mydb -e "select count(status), status from
> > table group by status order by null"
> >
> > to instead something like:
> >
> > mysql -hhost -uanonymous mydb -e "select status from table order by
> > null" | perl "give me the count numbers"
If the number of distinct "status" is small, then
... | perl -lne '$h{$_}++; END {print "$_\t$h{$_}" foreach keys %h}'
There is a possibility that when used in this way, mysql will read the
entire table into memory before starting to write it out to the pipe. If
so, there is a way to tell it not to. I don't recall which is the default.
You might want to look into that.
If you use DBI, which may be a good idea, then I know the default is to
read the results into memory up front, which would probably be a bad idea
(because if the results were small enough to fit in memory, you'd probably
just stick with using the mysql group by in the first place.
> If the table is large that's a major "lose"
Or not. AFAICT, mysql's "group by" always uses a sort, even when a hash
would be much more efficient. Perl uses whatever you tell it to.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 09 Jun 2008 10:50:54 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: TCP apllications
Message-Id: <86d4mqvc81.fsf@lifelogs.com>
On Fri, 6 Jun 2008 22:05:26 -0700 (PDT) SPX2 <stefan.petrea@gmail.com> wrote:
S> On Jun 6, 5:40 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>> Learn how TCP/IP works, from ARP to the SYN/ACK sequence to session
>> management. You don't need to become an expert, just be aware of what
>> happens on the wire. Then you'll understand your application much
>> better and your skills will go beyond "I can open a port and
>> listen/write to it." Also, writing the Perl application will be much
>> easier if you know what's going on underneath and what problems TCP/IP
>> may cause.
S> there's also a book on this.
S> it's called Network Programming in Perl - Lincoln D. Stein
S> http://www.google.com/search?hl=en&client=opera&rls=en&hs=DMB&q=lincoln+d.+stein+networking+perl&btnG=Search&lr=
S> the book is very appropriate for what you want to learn.
While NPiP is a good book, it's not going to cover the basics of TCP/IP
like the Stevens classic "TCP/IP Illustrated, Volume 1"
(http://www.kohala.com/start/tcpipiv1.html) so I'd recommend that book
very highly as well. NPiP covers the basics very quickly,
understandably since that's not its focus.
Ted
------------------------------
Date: Mon, 09 Jun 2008 10:19:35 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Tk with Thread
Message-Id: <5neq44h5i0h2o9nchf6em23van8sbn0hjd@4ax.com>
On Sun, 8 Jun 2008 14:58:30 -0700 (PDT), Slickuser
<slick.users@gmail.com> wrote:
>I try to use Excel OLE but it crashes when I click exit.
>Is there a way to work around?
>
>use strict;
>use warnings;
>#use Win32::OLE;
>#use Win32::OLE::Const 'Microsoft Excel';
>use Tk;
>use Tk::Balloon;
>use threads;
>use threads::shared;
>
>my $run:shared = 0;
>my $exit:shared = 0;
>my $count:shared = 0;
>
>
> my $thr = threads->new(\&new_thread);
>
I don't use windows, but your code runs fine for me (without the OLE
modules).
It's possible that Win32 OLE is not threadsafe, and if a thread dies(
crashes) it will take the main thread too.
As a guess, you might want to move the OLE modules use declarations down
into the thread code block, and see if that works.
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html
------------------------------
Date: Mon, 9 Jun 2008 08:22:12 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: Tk with Thread
Message-Id: <a39c8e03-0833-4944-9e8b-b306dde5c954@m36g2000hse.googlegroups.com>
When I move the use OLE to where I want to use it. Here's the error I
get.
Free to wrong pool 2db6e00 not 222dc8 during global destruction.
use strict;
use warnings;
use Tk;
use threads;
use threads::shared;
my $run:shared = 0;
my $exit:shared = 0;
my $count:shared = 0;
my $thr = threads->new(\&new_thread);
my $mainWindow = MainWindow->new;
my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7,
-scrollbars=>"ose", -wrap=>"word")->pack();
$mainWindow->Button(-foreground=>"blue", -text=>"Click",
-command=>\&excecute)->pack();
my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Stop",
-command=>sub{ $run=0; })->pack();
$mainWindow->Button(-foreground=>"black", -text=>"exit",
-command=>sub{ $exit=1;
$thr->join;
exit;
})->pack();
my $repeater = $mainWindow->repeat(1000,sub{
if($run){
$textBox->insert('end', "$count\n");
$textBox->see('end');
$textBox->update;
#$stopBut->configure(-state=> "disabled");
}
});
MainLoop;
sub new_thread{
while(1)
{
if($exit){ return; } #thread can only be joined after it
returns
if($run)
{
if($exit){return;}
&test;
}
else
{
## Sleep for 1 miliseconds
select(undef,undef,undef,.1);
}
}
}
sub test{
$count++;
#$::stopBut->configure(-state=> "disabled");
}
sub excecute {
$run = 1 ;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
}
------------------------------
Date: Mon, 9 Jun 2008 11:18:13 -0700 (PDT)
From: Nene <rodbass63@gmail.com>
Subject: use DBI
Message-Id: <77620bc5-5b53-489e-871e-f6ec3edb5231@d1g2000hsg.googlegroups.com>
Greetings:
I would like to put the DBI module on a linux box that does not have
the mysql client installed, is that possible? Since I'm not allowed
to install the module on the box, I did a perl MakeFile.pl prefex=/
blah/blah on my box and copied it over to the other box. I'm getting
the following error:
Can't locate loadable object for module DBI in @INC (@INC contains: /c
$/ctestsocket/perl/lib/perl5/site_perl/5.8.5//x86_64-linux /c$/
ctestsocket/perl/lib/perl5/site_perl/5.8.5/ /etc/perl /usr/lib/perl5/
site_perl/5.8.5/x86_64-linux /usr/lib/perl5/site_perl/5.8.5 /usr/lib/
perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/x86_64-linux /usr/lib/
perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/
perl5/5.8.5/x86_64-linux /usr/lib/perl5/5.8.5 /usr/local/lib/
site_perl .) at DBI.pm line 263
BEGIN failed--compilation aborted at DBI.pm line 263.
Compilation failed in require at ./dbi.pl line 4.
BEGIN failed--compilation aborted at ./dbi.pl line 4.
#################################################################
Line 263 of DBI.pm says:
247 # If you get an error here like "Can't find loadable object ..."
248 # then you haven't installed the DBI correctly. Read the
README
249 # then install it again.
250 if ( $ENV{DBI_PUREPERL} ) {
251 eval { bootstrap DBI } if $ENV{DBI_PUREPERL} == 1;
252 require DBI::PurePerl if $@ or $ENV{DBI_PUREPERL} >= 2;
253 $DBI::PurePerl ||= 0; # just to silence "only used once"
warnings
254 }
255 else {
256 bootstrap DBI;
257 }
258
259 $EXPORT_TAGS{preparse_flags} = [ grep { /^DBIpp_\w\w_/ } keys %
{__PACKAGE__."::"} ];
260
261 Exporter::export_ok_tags(keys %EXPORT_TAGS);
262
263 }
264
265 # Alias some handle methods to also be DBI class methods
266 for (qw(trace_msg set_err parse_trace_flag parse_trace_flags))
{
267 no strict;
268 *$_ = \&{"DBD::_::common::$_"};
269 }
Any clue? Thanks in advance.
usaims
------------------------------
Date: Mon, 09 Jun 2008 14:27:04 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: use DBI
Message-Id: <484d75fc$0$3367$4c368faf@roadrunner.com>
Nene wrote:
> I would like to put the DBI module on a linux box that does not have
> the mysql client installed, is that possible? Since I'm not allowed
> to install the module on the box, I did a perl MakeFile.pl prefex=/
> blah/blah on my box and copied it over to the other box. I'm getting
> the following error:
[snip]
>
> Line 263 of DBI.pm says:
[snip]
Lines 247-249 say:
>
> 247 # If you get an error here like "Can't find loadable object ..."
> 248 # then you haven't installed the DBI correctly. Read the README
> 249 # then install it again.
[snip]
From your description and the comment above, you clearly haven't
installed DBI correctly.
------------------------------
Date: Mon, 09 Jun 2008 14:32:54 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: use DBI
Message-Id: <484d8566$0$87078$815e3792@news.qwest.net>
Nene wrote:
> Greetings:
>
> I would like to put the DBI module on a linux box that does not have
> the mysql client installed, is that possible?
Read the installation docs for DBD::mysql, specifically the prerequisites:
...
MySQL
You need not install the actual MySQL database server, the client
files and the devlopment files are sufficient. [...]
[ nice spelling.. :-) ]
http://search.cpan.org/src/CAPTTOFU/DBD-mysql-4.007/INSTALL.html#prerequisites
> Since I'm not allowed
> to install the module on the box, I did a perl MakeFile.pl prefex=/
> blah/blah on my box and copied it over to the other box. I'm getting
> the following error:
Really? prefex=... well, there's your problem.. :-)
perldoc -q "How do I keep my own module/library directory"
Also, don't copy the files, copy the distribution, or use CPAN, and
do the make commands on 'the other box'.
------------------------------
Date: Mon, 9 Jun 2008 13:04:19 -0700 (PDT)
From: Nene <rodbass63@gmail.com>
Subject: Re: use DBI
Message-Id: <4d4a979c-10f0-45eb-8f31-0ca78bd960fd@m44g2000hsc.googlegroups.com>
On Jun 9, 3:32 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> Nene wrote:
> > Greetings:
>
> > I would like to put the DBI module on a linux box that does not have
> > the mysql client installed, is that possible?
>
> Read the installation docs for DBD::mysql, specifically the prerequisites:
I will do that, thanks.
> ...
> MySQL
>
> You need not install the actual MySQL database server, the client
> files and the devlopment files are sufficient. [...]
How do I do that? Sorry for the stupid question.
>
> [ nice spelling.. :-) ]
Seems like it will take longer to type 'nice spelling' then to correct
the mistake :-)
>
> http://search.cpan.org/src/CAPTTOFU/DBD-mysql-4.007/INSTALL.html#prer...
>
> > Since I'm not allowed
> > to install the module on the box, I did a perl MakeFile.pl prefex=/
> > blah/blah on my box and copied it over to the other box. I'm getting
> > the following error:
>
> Really? prefex=... well, there's your problem.. :-)
>
> perldoc -q "How do I keep my own module/library directory"
>
> Also, don't copy the files, copy the distribution, or use CPAN, and
> do the make commands on 'the other box'.
I can't do a 'make' on the other box, it doesn't have make installed
or gcc. Nor am I allowed to install it.
------------------------------
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 V11 Issue 1624
***************************************