[28294] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9658 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 28 14:05:54 2006

Date: Mon, 28 Aug 2006 11:05:06 -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, 28 Aug 2006     Volume: 10 Number: 9658

Today's topics:
    Re: Allowing threading with CGI <glex_no-spam@qwest-spam-no.invalid>
    Re: Allowing threading with CGI xhoster@gmail.com
    Re: Better performance ... <bg1act@yahoo.com.au>
    Re: Better performance ... <mritty@gmail.com>
    Re: Better performance ... <rvtol+news@isolution.nl>
    Re: Better performance ... <glex_no-spam@qwest-spam-no.invalid>
    Re: DBI Performance Issues <chris@thezengarden.net>
    Re: DBI Performance Issues xhoster@gmail.com
    Re: hi <tadmc@augustmail.com>
        How to read a pdf file using active perl? <alwinjohnson@gmail.com>
    Re: How to read a pdf file using active perl? <David.Squire@no.spam.from.here.au>
        integrate() <rvtol+news@isolution.nl>
    Re: Mail-IMAPClient problem and suggestion needed <glex_no-spam@qwest-spam-no.invalid>
    Re: Mail-IMAPClient problem and suggestion needed <David.Squire@no.spam.from.here.au>
    Re: Out of memory! When running perl script on windows <felad@walla.co.il>
    Re: Out of memory! When running perl script on windows <rvtol+news@isolution.nl>
    Re: Out of memory! When running perl script on windows xhoster@gmail.com
        printing a multidimensional array in table format <joelingram@gmail.com>
    Re: printing a multidimensional array in table format <nobull67@gmail.com>
    Re: Problem handling a Unicode file <rvtol+news@isolution.nl>
    Re: Problem handling a Unicode file <nobull67@gmail.com>
    Re: read file backwards xhoster@gmail.com
    Re: Threading - share xhoster@gmail.com
    Re: unsolved <tadmc@augustmail.com>
    Re: unsolved <someone@example.com>
    Re: What bless() do actually? <David.Squire@no.spam.from.here.au>
    Re: What bless() do actually? (Marc Espie)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 28 Aug 2006 10:42:32 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Allowing threading with CGI
Message-Id: <44f30dcb$0$10306$815e3792@news.qwest.net>

alpha_beta_release wrote:
> It doesn't work either. I modify this code from the example given.
> 
> [code]------------------------------
> #!c:/perl/bin/perl -Tw
> 
> use strict;
> use Parallel::ForkManager;
> use CGI;
> use CGI::Carp 'fatalsToBrowser';
> 
>   my $max_procs = 5;
>   my @names = qw( Fred Jim Lily Steve Jessica Bob Dave Christine Rico
> Sara );
> 
>   my $pm =  new Parallel::ForkManager($max_procs);
>   $pm->run_on_finish(
>     sub {
>         my ($pid, $exit_code, $ident) = @_;
>     }
>   );
> 
>   $pm->run_on_start(
>     sub {
>         my ($pid,$ident)=@_;
>     }
>   );
> 
>   $pm->run_on_wait(
>     sub {},
>     0.5
>   );
> 
>   foreach my $child ( 0 .. $#names ) {
>     my $pid = $pm->start($names[$child]) and next;
>    # $pm->finish($child);
>   }
> 
>   my $page = new CGI;
>   print $page->header,
>         $page->start_html,
>         'xxxxxx',
>         $page->end_html;
> 
> [/code]----------------------------
> 
> None of error messages, except system error :(

That's not very helpful.  What system error?

> 
> Is this (might be) because the system won't allow anonymous to run
> threads and eat system resources?

No.  Before jumping to Parallel::ForkManager, read up on how CGI works.

use CGI;
use Parallel::ForkManager;

my $page = new CGI;
print $page->header,
       $page->start_html;

my $max_procs = 5;
my @names = qw( Fred Jim Lily Steve Jessica Bob Dave Christine Rico Sara );

my $pm =  new Parallel::ForkManager($max_procs);

for my $child ( 0 .. $#names ) {
	my $pid = $pm->start($names[$child]) and next;
	print "Running $names[$child] pid=$pid<br> ";
	sleep 1;
	$pm->finish($child);
}

$pm->wait_all_children();

print $page->end_html();


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

Date: 28 Aug 2006 16:08:51 GMT
From: xhoster@gmail.com
Subject: Re: Allowing threading with CGI
Message-Id: <20060828120920.050$rG@newsreader.com>

"alpha_beta_release" <youknows@gmail.com> wrote:
> Hi,
>
> I'm doing CGI, and plan to use threads.pm for CGI application. I ran a
> test, but unfortunately, my http server (Apache) won't allow multiple
> threads ran within a CGI script. But the script works OK if not as CGI
> and as local running script. Any suggestion?

Yeah, tells what the problem is.  Did you get the notorious
"Neener-neener, your mom wears combat boots at line 42" error?

Xho

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


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

Date: 28 Aug 2006 06:54:44 -0700
From: "goho" <bg1act@yahoo.com.au>
Subject: Re: Better performance ...
Message-Id: <1156773284.624888.248110@m79g2000cwm.googlegroups.com>


cms-team@ivi.de wrote:
> Thx a lot. This does the trick.
>
> Performance went up from 50 minutes runtime for 30 scripts (tables) to
> 10 minutes!!!
>
> Greetings
> Marcus

Your problem doesn't have a lot to do with perl; I suggest you look
towards the mysql group, however, that said:

I've not used MySQL but from experience with other DBMS you may get
significant improvement by creating the pvsnr and vm keys (indexes)
AFTER loading the data.

In some databases it helps to offline pre-sort in order of the primary
key - try it. Without knowing the internal structure of InnoDB I cant
say whether it will improve things or be a disaster but you wont know
until you try.

Be aware of ROLLBACK issues if you dont regularly commit; not a subject
for discussion here, I'll leave that for you to follow up. If you are
looking for a book, Michael Kofler's 'The Definitive Guide to MySQL'
looks pretty reasonable

Good luck.



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

Date: 28 Aug 2006 07:18:14 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Better performance ...
Message-Id: <1156774694.036539.147760@b28g2000cwb.googlegroups.com>

cms-team@ivi.de wrote:
> I've got the following code and would like to ask, if there is any
> possibilty for more performance. The script inserts about 240
> recordsets per second into a MySQL database.


<snip>

> while (<FP1>)
> {
> 	$line = $_;

Why make two assignments?

while (my $line = <FP1>) {

> 	chop ($line);

You want chomp(), not chop().  There is a difference.  Look at perldoc
-f chomp and perldoc -f chop

> 	$linecount += 1;

No need for this variable.  Perl maintains the linecount in the $.
variable for you.

>
> 	$line=~s/\"//g;
> 	($apl,$vsnr1,$vsnr2,$pvsnr,$art,$aktiv,$vmnr,$vbeginn,$vende,$zw,$ikm,$ktoidx,$nettobeitrag,$bruttoratenbeitrag,$produkttext,$rohbau)
> = split(/;/,$line);
>
> 	$vende=~s/ *$//g;
> 	$vende=~s/,/\./g;
>
> 	$ktoidx=~s/ *$//g;
> 	$ktoidx=~s/,/\./g;
>
> 	$nettobeitrag=~s/ *$//g;
> 	$nettobeitrag=~s/,/\./g;
>
> 	$bruttoratenbeitrag=~s/ *$//g;
> 	$bruttoratenbeitrag=~s/,/\./g;
>
> 	$produkttext=~s/ *$//g;
> 	$produkttext=~s/,/\./g;
>
> 	$rohbau=~s/ *$//g;
> 	$rohbau=~s/,/\./g;

For readability sake, make this one for loop that iterates over your
six variables.  For performance sake, change the * to a + and change
the second s///g to a tr///

for ($vende, $ktoidx, $nettobeitrag, $bruttoratenbeitrag, $producttext,
$rohbau) {
   s/ +$//g;
   tr/,/./;
}

>
> 	$statment="INSERT into testtabelle
> (apl,vsnr,pvsnr,art,aktiv,vmnr,vbeginn,vende,zw,ikm,ktoidx,nettobeitrag,bruttoratenbeitrag,produkttext,rohbau)
> value
> ('$apl','$vsnr1$vsnr2','$pvsnr','$art','$aktiv','$vmnr','$vbeginn',".($vende
> eq "" ? "NULL" : "'".$vende."'").",$zw,'$ikm',".($ktoidx eq "" ? "NULL"
> :
> "'".$ktoidx."'").",$nettobeitrag,$bruttoratenbeitrag,'$produkttext',".($rohbau
> eq "" ? "NULL" : "'".$rohbau."'").")";
>
> 	$rv=$dbh->do($statment);

Here's a large performance hit.  Instead of compiling this SQL each
time through, prepare this SQL *once*, outside the loop.  Then execute
it many times in the loop.

#outside the loop:
my $statement = <<"EO_SQL";
INSERT INTO testabelle
(apl,vsnr,pvsnr,art,aktiv,vmnr,vbeginn,vende,zw,ikm,ktoidx,nettobeitrag,bruttoratenbeitrag,produkttext,rohbau)
VALUE
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
EO_SQL
my $sth = $dbh->prepare($statement);
#...

#later, inside the loop:
$sth->execute($apl, $vsnr1 . $vnsr2, $pvsnr, $art, $aktiv, $vmnr,
$vbeginn, ($vende eq q{} ? 'NULL' : $vende), $zw, $ikm, ($ktoidx eq q{}
? 'NULL' : $ktoidx), $nettobeitrag, $bruttoratenbeitrag, $produkttext,
($rohbau eq q{} ? 'NULL' : $rohbau));

You'll note that this also saves you the annoyance of having to figure
out all those quotes in your original SQL.


The previous recommendations given to you are good - committing only
after all the inserts will definately save you time - but this should
help as well.

Paul Lalli



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

Date: Mon, 28 Aug 2006 17:09:19 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Better performance ...
Message-Id: <ecv87n.lo.1@news.isolution.nl>

cms-team@ivi.de schreef:

> $vende=~s/ *$//g;

I don't think the g-modifier is needed. Also change the "*" to a "+",
but Paul already showed you that.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Mon, 28 Aug 2006 10:55:17 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Better performance ...
Message-Id: <44f310c7$0$10301$815e3792@news.qwest.net>

cms-team@ivi.de wrote:
> Hy!
> 
> I've got the following code and would like to ask, if there is any
> possibilty for more performance. The script inserts about 240
> recordsets per second into a MySQL database.
> 
> The file (input.txt) contains about 365.000 lines/recordsets.

Also, see MySQL specific techniques, especially "LOAD DATA INFILE", 
which they say "is usually 20 times faster than using INSERT statements."

http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html


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

Date: Mon, 28 Aug 2006 10:37:31 -0400
From: "Chris H." <chris@thezengarden.net>
Subject: Re: DBI Performance Issues
Message-Id: <pan.2006.08.28.14.37.30.943460@thezengarden.net>

On Fri, 25 Aug 2006 17:56:42 +0000, xhoster wrote:
> 
> How fast is your network connection?  I see barely any change in
> performance at all between local and remote.
> 

the real machine will be 100mbit to 100mbit via lan. the testing machines
that i used are from my home cable connection (8mb down/2mb up) to 100mbit
colo. its easy to blame the cable connection, however the traffic going
across the line during the updates are a whopping 7kbit/s which a 14.4k
could handle. thats why im at a loss for ideas. its like its refusing to
use the cpu or the network hardware during remote tests. as i dont have
iptraf on the actual machine that will run this, i cant say for certain
how much bandwidth its using on the lan...but i'd imaging not much if any
more than my home to colo tests.


> I would suggest it is at a lower lever, at the network or at the compiled
> binaries that DBD::mysql links against.  Have you implemented the same
> thing in another language (C, Java, Python) and seen better performance?
> If not, I doubt your problem has anything to do with Perl or perl modules
> per se.
> 
> Xho

i have not implemented this in another language, however, there are a few
changes. first the live script is run from a sun solaris machine using
dbi's sybase odbc driver to connect to a mssql database on a windows 2003
server machine. the dev script i've modified to suit my environment which
consists of mysql. the tables i have set up identical, and the data file
was scp'ed from the live machine and run against both databases to check
for performance differences.

the only difference short of this i can find is that on my colo box
running mysql local, and running the script local with 'localhost' as the
server to connect to will use 50% cpu for the perl script, and 50% cpu for
the mysql process.

running it from my home machine to the mysql box using 'domain.tld' as the
server to connect to, it uses less than .5% cpu as if its not even working
or attempting to work.

this effect is seen in the live version of the script too, with the remote
server in the connect string, the script on the solaris box will use less
than 1% cpu and the mssql server machine under task manager reports a cpu
usage of 8%-14% (it doesnt run this database exclusively).

i realize there are quite a few variables at play here, but im hoping its
something really simple im missing thats blocking it from just running at
its true speed.

i cant say how the dbi or dbd drivers on the solaris machine are compiled,
as i didnt set them up. the dbi and dbd drivers on both my home machine
and the colo box are standard gentoo compiled versions. as far as the
ebuild's are concerned, they are setting no additional options from the
defaults.

thanks.

-- 
Chris H.
http://www.nasland.nu



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

Date: 28 Aug 2006 16:27:31 GMT
From: xhoster@gmail.com
Subject: Re: DBI Performance Issues
Message-Id: <20060828122800.257$os@newsreader.com>

"Chris H." <chris@thezengarden.net> wrote:
> On Fri, 25 Aug 2006 17:56:42 +0000, xhoster wrote:
> >
> > How fast is your network connection?  I see barely any change in
> > performance at all between local and remote.
> >
>
> the real machine will be 100mbit to 100mbit via lan. the testing machines
> that i used are from my home cable connection (8mb down/2mb up) to
> 100mbit colo. its easy to blame the cable connection, however the traffic
> going across the line during the updates are a whopping 7kbit/s which a
> 14.4k could handle. thats why im at a loss for ideas.

You are not making the important distiction between throughput and latency.
Your Perl script sends the sql command, then waits to get a response.
While waiting, it does nothing--it doesn't use CPU and/or bandwidth by
"sending ahead on prospect" more update statements.  So you are limited by
latency, not by throughput.  With an insert, you can circumvent this by
using the MySQL-specific multiple row insert statement to add many rows per
network round-trip.  Maybe you can use the MySQL-specific "INSERT...ON
DUPLICATE KEY UPDATE" syntax to accomplish the same thing--just a
suggestion, I've never looked into it in detail myself.  However, if your
real situation will have the two machines on the same LAN, then latency
will probably not be a problem.  You simply can't do benchmarking on such
disparate setups and expect the results to be meaningful.

Xho

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


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

Date: Mon, 28 Aug 2006 09:26:05 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: hi
Message-Id: <slrnef5v7t.8q6.tadmc@magna.augustmail.com>

sivasish <ssivasish@yahoo.co.in> wrote:

> please help me out


OK.

Here is some help:

   Put the subject of your article in the Subject of your article!


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


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

Date: 28 Aug 2006 06:21:34 -0700
From: "johny" <alwinjohnson@gmail.com>
Subject: How to read a pdf file using active perl?
Message-Id: <1156771293.995631.179630@i3g2000cwc.googlegroups.com>

Hi,
I am trying to read a PDF file using active Perl. I tried with
PDF::API2 but no use. For example - I should get the text which is on
the third line of first page...

or

Is there any way where I can save the pdf file as a .txt file and then
read the file?
Please help........ 

Thanks, 
AJ



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

Date: Mon, 28 Aug 2006 14:45:05 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: How to read a pdf file using active perl?
Message-Id: <ecus11$m29$1@gemini.csx.cam.ac.uk>

johny wrote:
> Hi,
> I am trying to read a PDF file using active Perl. I tried with
> PDF::API2 but no use. For example - I should get the text which is on
> the third line of first page...
> 
> or
> 
> Is there any way where I can save the pdf file as a .txt file and then
> read the file?
> Please help........ 

Do you need to use Perl? There is the command-line utility pdftotext 
that is available on most UNIX-like systems (and no doubt cygwin).

You need to be aware that there is no guarantee that you can get text 
out of a PDF document. The PDF standard allows arbitrary encodings to be 
used, so you would have to know what the glyph names mean to reconstruct 
the text. In some cases the glyph names are not meaningful. See 
http://www.glyphandcog.com/textext.html

That being said, pdftotext works in the great majority of cases.


DS


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

Date: Mon, 28 Aug 2006 16:27:40 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: integrate()
Message-Id: <ecv5ia.12s.1@news.isolution.nl>

I found this interesting example on comp.lang.misc
<news:44f24874$0$3585$ed2e19e4@ptn-nntp-reader04.plus.net>
that I think would be nice to translate to Perl.


> The following Mathematica code implements polynomial integration
> using only Mathematica's pattern matcher and the FreeQ[e, f] function
> (which checks that the pattern "f" does not match any subexpression
> of "e"):
>
> integrate[y_ + z_ , x_] :=   integrate[y, x] + integrate[z, x]
> integrate[c_ y_   , x_] := c integrate[y, x] /; FreeQ[c, x]
> integrate[c_      , x_] := c x               /; FreeQ[c, x]
> integrate[x_^n_.  , x_] := x^(n + 1)/(n + 1) /; FreeQ[n, x] && n != -1
>
> For example:
>
> integrate[3 a x^2 + 2 b x + c, x]
> => c x + b x^2 + a x^3

That seems to come from
  http://documents.wolfram.com/mathematica/book/section-2.3.14
which also mentions:

  integrate[ 1/(a_. x_ + b_.), x_] := Log[a x + b]/a /; FreeQ[{a,b}, x]
  integrate[Exp[a_. x_ + b_.], x_] := Exp[a x + b]/a /; FreeQ[{a,b}, x]


I assumed that somebody would have done something in this area already
(without calling Mathematica), so I checked CPAN, but I found nothing
for polynomial integration, so I probably just didn't look well enough,
did I?


Note that you can write the (trivial) example as

  ['c', '2 b', '3 a']  -->  ['', 'c', 'b', 'a']

A variant:

  ['c', 'b', 'a']  -->  ['', 'c', 'b / 2', 'a / 3']


See also google: mathematica FreeQ.
http://documents.wolfram.com/mathematica/book/section-1.8.5
http://www.physic.ut.ee/~kkannike/english/prog/mathematica/patterns/index.html

Legenda:
  "^n." : the trailing "." means optional. If absent, than 1 is used.
          Perlish: /(\d+)/ ? $1 : 1
  "/;"  : constraint follows.
          Perlish: if ...


Solution-1: s/.*/c x + b x^2 + a x^3/
;)

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Mon, 28 Aug 2006 10:18:22 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Mail-IMAPClient problem and suggestion needed
Message-Id: <44f30820$0$34069$815e3792@news.qwest.net>

debhatta@gmail.com wrote:
> Hi
> 
> There are two issues for which I would like your opinion. First let me
> post a bit of code :
> 
> use Mail::IMAPClient;
> use strict;
> use diagnostics;
> my $imap = Mail::IMAPClient->new(
>                 Server          => $imap_server ,
>                 User            => $user_id ,
>                 password        => $password,
>                 Uid             => 1, # Optional
>             ) or die "cant connect to imap server, $!";

) or die "cant connect to imap server, $@"; # Use $@ instead of $!

> $imap->select("INBOX");
> my @msgs = $imap->search("ALL");
> foreach my $msg (@msgs) {

You could avoid @msgs.

for my $msn ( @{ $imap->search("ALL") } )

>                print "This is $msg\n";
>              my @flags = $imap->flags($msg) or die " could not flags:
> $!";
>               my $i;
>              for ( $i=0;$i<@flags;$i++) {

and make $i only available within the for loop.

for my $i ( 0 .. $#flags )

>                         print "The flag is $flags[$i]\n";
>             }
> ..... etc.
> 
> Say there is one message in the INBOX, then the o/p of the above code
> is
> 
> This is 26006
> Uncaught exception from user code:
>          could not flags:  at auto2.pl line 51.
> 
> Can anyone tell me why its failing while retrieving the flags ? Is it
> because there are no flags set ?

Why not have it tell you?

my @flags = $imap->flags($msg) or die "Could not get flags for msg:$msg: 
$@"; # use $@ instead of $!

> 
> 
> Secondly I want your opinion on my approach. 
 .. I can't help you there..



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

Date: Mon, 28 Aug 2006 16:21:06 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Mail-IMAPClient problem and suggestion needed
Message-Id: <ecv1l3$3en$1@gemini.csx.cam.ac.uk>

J. Gleixner wrote:
> debhatta@gmail.com wrote:

>> $!";
>>               my $i;
>>              for ( $i=0;$i<@flags;$i++) {
> 
> and make $i only available within the for loop.
> 
> for my $i ( 0 .. $#flags )
> 
>>                         print "The flag is $flags[$i]\n";
>>             }
>> ..... etc.

Why not avoid $i altogether?

foreach my $flag (@flags) {
	print "The flag is $flag\n";
}


or even

print "The flag is $_\n" for @flags;

(These also avoids any potential pathological weirdness if someone has 
messed around with the array indexing start value)


DS


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

Date: 28 Aug 2006 08:00:40 -0700
From: "felad" <felad@walla.co.il>
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <1156777240.113863.98350@h48g2000cwc.googlegroups.com>

Hi

The script is very long so I don't think it will help
Still couldn't find the problem but now I was thinking about printing
how much memory the program \ process takes in several functions to try
to find the problem
Which perl module I can use to print the memory the script takes ?

Thanks



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

Date: Mon, 28 Aug 2006 17:33:08 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <ecv9du.19s.1@news.isolution.nl>

alpha_beta_release schreef:

> 2- undef not-used variable in the middle of script (sometimes these
> variables hold huge   data from file, and used only before parsing).
> So undef after parsing, and before doing other task, to save memory.

The variable needs to get out of scope AND not being referenced anymore,
for the memory to be returned.

  perldoc -q memory
  perldoc -q shrink

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 28 Aug 2006 16:43:33 GMT
From: xhoster@gmail.com
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <20060828124401.878$aB@newsreader.com>

"felad" <felad@walla.co.il> wrote:
> Hi
>
> I have Perl program on windows that suppose to run on about 10,000
> items in a loop ( should take 2-3 days for it to run )

Wow, that is a long time for 10,000 items.  What are you doing to them?

> The problem is that after several hours I get this error:
> Out of memory!
> Callback called exit.
>
> I have found that every single loop the commit memory grow by 6000 K so
> I guess this is why the program crash
> But I really can't find that cause of it, most of my variable are local
> and I can't find any infinite loop
>
> Any ideas ?

It is hard to say without knowing more.  If each item is processed
seperately (i.e. results of current item don't depend on results of past
items) then it should be easy to add a "next" or "return" part way through
the processing code, so that each item is only partially processed.  Move
the next or return statement around in a binary search-like way to figure
out where the leak is triggered.  Montior the memory useage closely so that
you can figure out if it is leaking without having to wait for 3 days
and/or for a OOM error.

Xho

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


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

Date: 28 Aug 2006 09:28:38 -0700
From: "joel" <joelingram@gmail.com>
Subject: printing a multidimensional array in table format
Message-Id: <1156782518.749956.284210@m79g2000cwm.googlegroups.com>

For any number of rows and columns of a multidimensional array, I would
like my printHandler subroutine to print in table format with minimal
effort. What is the easiest way of doing this?

{
	...
	...
	while (my (@array)=($sth->fetchrow_array()))
	{
		push(@result,[@array]);
	}
	&printHandler(@result);
}

sub printHandler
{
	my $i=0;
	foreach (@_)
	{
		print "@{$_[$i]}\n";
		$i++;
	}
}

current output:
4591 05-00371
149817 06-02930
15541 06-0369
827 04-00307
13406 06-01364

desired output:
4591   05-00371
149817 06-02930
15541  06-0369
827    04-00307
13406  06-01364



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

Date: 28 Aug 2006 10:02:04 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: printing a multidimensional array in table format
Message-Id: <1156784524.773546.227020@p79g2000cwp.googlegroups.com>


joel wrote:
> For any number of rows and columns of a multidimensional array, I would
> like my printHandler subroutine to print in table format with minimal
> effort. What is the easiest way of doing this?
>
> {
> 	...
> 	...
> 	while (my (@array)=($sth->fetchrow_array()))

All those parentheses don't really add clarity...

	while (my @array = $sth->fetchrow_array )

> 	{
> 		push(@result,[@array]);
> 	}

Since @array is declared within the loop (good!) you don't need to make
a copy of it, you can push a reference to @array itself as you'll get a
new @array on the next iteration.

 		push(@result,\@array);

> 	&printHandler(@result);

Do you know what the & there does?  If not then remove it.

As a general rule you should pass arrays to subroutines using array
references rather than unrolling the array into a list and passing each
element of the array as a separate argument.

	printHandler(\@result);

BTW: have you considered using fetchall_arrayref?

> sub printHandler
> {
> 	my $i=0;
> 	foreach (@_)
> 	{
> 		print "@{$_[$i]}\n";
> 		$i++;
> 	}
> }

Ouch! You put each element of @_ in turn into $_ and then ignore that
and hand carft a loop index to use as a subscript.

        foreach (@_)
 	{
 		print "@{$_}\n"; # {} strictly redundant
	}

Or if you'd passed an array ref...

        my ($list)= @_;
        foreach (@$list)
 	{
 		print "@$_\n";
	}


> current output:
> 4591 05-00371
> 149817 06-02930
> 15541 06-0369
> 827 04-00307
> 13406 06-01364
>
> desired output:
> 4591   05-00371
> 149817 06-02930
> 15541  06-0369
> 827    04-00307
> 13406  06-01364

Ah, you want to print the output formatted.  Perl has a "print
formatted" function ..

        my ($list)= @_;
        for (@$list)
 	{
 		printf "%6s %s\n",@$_;
	}

Or if you feel terse..

 		printf "%6s %s\n",@$_ for @{+shift};



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

Date: Mon, 28 Aug 2006 17:40:13 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Problem handling a Unicode file
Message-Id: <ecv9qa.1ac.1@news.isolution.nl>

MoshiachNow schreef:

> I use the code below,but the file does not look good in Notepad
> anymore,meaning the format is not exactly utf16 ...
>
> open (FILE,'<:encoding(utf16)',"Araxi.reg") || die "Could not open
> Araxi.reg: $!"; #Read UNICODE FILE TO ASCII
> open (FILE1,">Araxi1.reg") || die "Could not open Araxi1.reg: $!";

You need to use the utf16le layer for the output to.

#!/usr/bin/perl
  use warnings ;
  use strict ;

  my $fni = 'Araxi.reg' ;
  my $fno = 'Araxi1.reg' ;

  open my $fhi, '<:encoding(utf16)', $fni
    or die "open '$fni', stopped $!" ;

  open my $fho, '>:encoding(utf16)', $fno
    or die "open '$fno', stopped $!" ;


-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 28 Aug 2006 10:08:26 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Problem handling a Unicode file
Message-Id: <1156784906.645892.264990@b28g2000cwb.googlegroups.com>


MoshiachNow wrote:

> 	open (FILE,'<:encoding(utf16)',"Araxi.reg") || die "Could not open
> Araxi.reg: $!"; #Read UNICODE FILE TO ASCII

That comment is highly missleading. It should say "Read utf16 file into
Unicode".

The file is in utf16. The strings that are read from it are in Unicode.
Actually Perl will internally represent the stings in utf8, but
conceptually they are just Unicode. One thing they certainly are not is
ASCII. Of course if the data happens to contain no characters beyond
0x7F then the internal represtation of the Unicode string will be
identical to the equivalent ASCII string.



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

Date: 28 Aug 2006 17:01:53 GMT
From: xhoster@gmail.com
Subject: Re: read file backwards
Message-Id: <20060828130222.401$Mv@newsreader.com>

kejoseph@hotmail.com wrote:

> Wow, I had no idea a simple query would resuilt in such hostility !
>
> Why do I not want to use a module ? Really simple, I then have to
> install the module on all the servers. If I were doing this on my test
> box it would be okay, but I plan to put this script on production
> servers ; not a couple or a dozen but around 50 or more.

OK.  No problem.  After all, you are going to put your script which uses
the module on 50 servers, why should it be a problem to put the module
it uses on 50 servers?

> Not just that,
> since this is perceived as a system change, I need to open a change
> control and obtain permission from various teams/managers !

But you don't need obtain permission to install your own home-rolled crap
on the servers?  Sorry, but if your management micromanages you to such
an extent that you can't get them to install a very popular CPAN module,
then you should be asking your management, not us, for the antidote to
their own cool-aid.

Xho

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


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

Date: 28 Aug 2006 17:26:21 GMT
From: xhoster@gmail.com
Subject: Re: Threading - share
Message-Id: <20060828132650.900$HX@newsreader.com>

"mumebuhi" <mumebuhi@gmail.com> wrote:
> I am trying to understand the differences among these constructs:
>
> # 1
> my $p : shared;
> $p->{'_name'} = "My Name";
>
> # 2
> my $p : shared = &share({});
> $p->{'_name'} = "My Name";
>
> Do 1 and 2 achieve the same thing?

No. 1 gives a "Invalid value for shared scalar" error in nontrivial
contexts.  2 doesn't (but overriding prototypes is probably bad form,
anyway).

# 2.5
my $p = share(%{+{}});
$p->{'_name'} = "My Name";

# 2.75
my $p={}; share %$p;
$p->{'_name'} = "My Name";

>
> # 3
> my %p : shared;
> $p{'_name'} = "My Name";
>
> Is it fair to say that 3 is the simpler form compared to 1 and 2?

In the sense that it is simpler to not use gratuitous references than it is
to use gratuitous references, sure, 3 is simpler.   But using the same
logic, we could say it is even simpler not to share the variables at all,
as you don't make meaningful use of the shared nature.  Whether you need
the complexity of sharing, or need the complexity of references, depends on
the parts of your code you haven't shown us.

Xho

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


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

Date: Mon, 28 Aug 2006 09:26:47 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: unsolved
Message-Id: <slrnef5v97.8q6.tadmc@magna.augustmail.com>

sivasish <ssivasish@yahoo.co.in> wrote:

> print the
> second string lined up over its copy at the end of the concatenated
> strings.


   perldoc -f printf


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


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

Date: Mon, 28 Aug 2006 16:38:11 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: unsolved
Message-Id: <TZEIg.17354$395.8678@edtnps90>

sivasish wrote:
> hi any body can help me to write this program
> 
> Q.prompt the user to enter two strins of dna.concatenate the two
> strings of DNA by appending the second to the first  using ".="
> operator. print the two strings as concatenated and then print the
> second string lined up over its copy at the end of the concatenated
> strings. for example
> input string are
> AAAAAA
> TTTTTT
> print as AAAAAATTTTTT
>                            TTTTTT
> 
> i wrote the code for the first part but not able proceed further.i.e
> how to print the above .

use warnings;
use strict;

print 'Enter the first string: ';
chomp( my $first = <STDIN> ):
print 'Enter the second string: ';
chomp( my $second = <STDIN> ):
print "$first$second\n";
$first =~ tr// /c;
print "$first$second\n";




John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 28 Aug 2006 14:31:44 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: What bless() do actually?
Message-Id: <ecur80$kjl$1@gemini.csx.cam.ac.uk>

Marc Espie wrote:
> In article <ecuo1q$e2p$2@gemini.csx.cam.ac.uk>,
> David Squire  <David.Squire@no.spam.from.here.au> wrote:
>> David Squire wrote:
>>> anno4000@radom.zrz.tu-berlin.de wrote:
> 
>>>> Polymorphism is rather a consequence of other features, not an 
>>>> independent feature.
> 
> 
>>> That is not the way it is seen (and taught) by many OO folk. It is 
>>> common to find textbooks and lecture notes that state something like:
> 
>>>     The essential elements of an OO language are inheritance, 
>>> encapsulation and polymorphism.
> 
>> Oh, and "abstraction" is often in that list too - but I would be happier 
>> saying that that is a consequence of inheritance (and perhaps polymorphism).
> 
> Personally, I would tend to put `abstraction' at the top.

In terms of importance yes, but is it a fundamental language property or 
a something constructed by coding? From a language point of view, it's 
about being about to have abstract classes (e.g. pure virtual functions 
in C++, interfaces in Java), which to me is all about inheritance.

> Inheritance and polymorphism are actually not really needed in many cases.
> 
> You can build OO languages without inheritance. Cloning prototype objects
> comes to mind.
> 
> This kind of behavior is even not too hard to build in perl, and I've
> built Object-oriented PostScript code in the past by using that technique.
> 
> The only `feature' you need for object-orientation is a way to associate
> code with data, namely have an operator so that o->f(args) will call an f
> which is dependent on o.
> 
> So any language with hashes and anonymous subs leads itself to object-oriented
> techniques in a very straightforward way: just let your hashes be objects,
> and key the anonymous subs with method names. Everything else, including
> using an extra indirection through a `class' to have uniform object behavior
> and save memory is just optimization. ;-)

Your definition of OO as no more than "code associated with data" is at 
odds with the currently accepted (academic) definition of what an OO 
language is. This is not a value judgment, just a statement of current 
dogma.

I have a lot of sympathy with your view, but ultimately I think this 
argument leads towards the conclusion that all Turing-complete languages 
are OO, since you could built such machinery out of them one way or 
another. It must surely be a question of what the language natively 
supports, rather than what can be built using it.

I think we need to make a distinction between OO languages and OO 
techniques. Years ago I wrote a widget set (before I was aware of that 
term) for SGI machines in C, using structs with function pointers to 
represent "widgets". In retrospect an OO technique, but that does not 
make C an OO language.


DS


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

Date: Mon, 28 Aug 2006 13:47:59 +0000 (UTC)
From: espie@lain.home (Marc Espie)
Subject: Re: What bless() do actually?
Message-Id: <ecus6f$1vl2$1@biggoron.nerim.net>

In article <ecur80$kjl$1@gemini.csx.cam.ac.uk>,
David Squire  <David.Squire@no.spam.from.here.au> wrote:
>Your definition of OO as no more than "code associated with data" is at 
>odds with the currently accepted (academic) definition of what an OO 
>language is. This is not a value judgment, just a statement of current 
>dogma.

I disagree. You're talking buzzwords and undergraduate academics.

All the stuff I've seen regarding semantics research and type checking,
for instance, boils down to extending traditional lambda-calculus somehow
to include object constructs.

Any half decent course on language theory/compilation/semantics will have
some reduction towards object = data + associated methods, together with
a discussion of space-constraint optimizations (e.g., vtables) and
type systems and their various limitations.


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

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


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