[29638] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 882 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 26 06:09:43 2007

Date: Wed, 26 Sep 2007 03:09:07 -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           Wed, 26 Sep 2007     Volume: 11 Number: 882

Today's topics:
    Re: Accessing array elements of record <ver_amitabh@yahoo.com>
    Re: Accessing array elements of record <zen13097@zen.co.uk>
        Deleting a section of file using perl <ver_amitabh@yahoo.com>
        get Hash of Array <ebmarquez@gmail.com>
    Re: get Hash of Array <jgibson@mail.arc.nasa.gov>
    Re: get Hash of Array <ben@morrow.me.uk>
    Re: how to make a runnable module (or modular script) ? <bugbear@trim_papermule.co.uk_trim>
    Re: how to make a runnable module (or modular script) ? <brian.d.foy@gmail.com>
    Re: how to make a runnable module (or modular script) ? <bugbear@trim_papermule.co.uk_trim>
        How to read and write a file without open file twice? T <needpassion@gmail.com>
    Re: How to read and write a file without open file twic <ben@morrow.me.uk>
    Re: How to read and write a file without open file twic <rkb@i.frys.com>
        How to set a COM Object property to TRUE  bmw108@gmail.com
    Re: How to set a COM Object property to TRUE <see.sig@rochester.rr.com>
    Re: how to show the fragment of element from array ? <zen13097@zen.co.uk>
    Re: import fails if package namespace != module path  neurocline@gmail.com
        new CPAN modules on Wed Sep 26 2007 (Randal Schwartz)
        Upgrading Bundle::CPAN freezes during tests <khym.chanur@gmail.com>
        why are references so slow ? <dduenker@uni-koblenz.de>
    Re: why are references so slow ? <brian.d.foy@gmail.com>
    Re: why are references so slow ? <nobull67@gmail.com>
    Re: why are references so slow ? <dduenker@uni-koblenz.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Sep 2007 00:14:19 -0700
From:  Ami <ver_amitabh@yahoo.com>
Subject: Re: Accessing array elements of record
Message-Id: <1190790859.515077.104300@57g2000hsv.googlegroups.com>

On Sep 25, 5:36 pm, Mirco Wahab <wa...@chemie.uni-halle.de> wrote:
> Ami wrote:
>
> my $record = {
>      NAME   => "Jason",
>      EMPNO  => 132,
>      TITLE  => "deputy peon",
>      AGE    => 23,
>      SALARY => 37_000,
>      PALS   => [ "Norbert", "Rhys", "Phineas"],
>
> };
> > 1: $byname{ $record->{NAME} } = $record;
> > 2: push @{$byname{"Jason"}->{PALS}}, "Theodore";
> > 3: @tt = ($byname{"Jason"}->{PALS});
> > 4: for ($i=0;$i<1;$i++)
> > 5: {
> > 6:   printf("PALS %s",$tt[$i]);
> > 7: }
>
> There are some problems here,
> 1 & 2 are o.k.:
>
>     my %byname;
>     $byname{ $record->{NAME} } = $record;
>     push @{$byname{"Jason"}{PALS}}, "Theodore";
>
> The next line is wrong, the "array" in the record
> is an "array reference":
>
>     my $tt = $byname{"Jason"}{PALS};
>
> You can drop the arrows between braces.
> By string interpolation of the array
> reference, you got your pals:
>
>     printf "PALS: @$tt \n";
>
> In a loop, one would write:
>
>     for my $t (@$tt) {
>        printf "PAL: %s, ", $t   # or printf "PAL: $t, "
>     }
> Regards
>
> M.

Hi Micro and Paul,
   Many thanks for your answers. It works great now with your help.
Thanks again,
Regards



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

Date: 26 Sep 2007 07:56:29 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Accessing array elements of record
Message-Id: <46fa10ad$0$8412$db0fefd9@news.zen.co.uk>

On Tue, 25 Sep 2007 05:17:00 -0700, Ami <ver_amitabh@yahoo.com> wrote:
> 
>  @tt = ($byname{"Jason"}->{PALS});
> 
>  for ($i=0;$i<1;$i++)
>  {
>    printf("PALS %s",$tt[$i]);
>  }

In addition to the other answers here, you could just
leave out your intermediate @tt array, and access the
array directly:

    printf("PALS %s", $byname{"Jason"}->{PALS}->[$i]);

Note that the "->" between backets is optional, as are
(generally speaking) the quotes around the hash key,
so it could be written as:

    printf("PALS %s", $byname{Jason}{PALS}[$i]);



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

Date: Wed, 26 Sep 2007 00:24:45 -0700
From:  Ami <ver_amitabh@yahoo.com>
Subject: Deleting a section of file using perl
Message-Id: <1190791485.124044.102210@22g2000hsm.googlegroups.com>

Hi All,
   I am reading and file and same time modifying it (Inline edit). I
store a particular position of file on some criteria using tell() and
than after reading some other stuff, i need to decide, if i want to
delete the contents of file from previously stored position till
current position.
It would be great help, if some one can give me idea/code snippet to
do it.
I need a code to delete file contents from one position to another
position and again continue processing file in same way.

Thanks in advance for your help.
Regards,



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

Date: Tue, 25 Sep 2007 19:47:35 -0000
From:  ebm <ebmarquez@gmail.com>
Subject: get Hash of Array
Message-Id: <1190749655.935172.183780@g4g2000hsf.googlegroups.com>

is there an easier way to capture the values from a hash of an array?
here's what %data looks like if I use Dumper
---------------------------------------------------
%data using Dumper
$VAR1 = bless( {
                 'fnames' => [
                               'OwnerID',
                               'FaxDateTime',
                               'ElapsedTime',
                               'Pages'
                             ],
                 'field' => {
                              'ElapsedTime' => 2,
                              'OwnerID' => 0,
                              'Pages' => 3,
                              'FaxDateTime' => 1
                            }
               }
);

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

		@keys = keys(%{$data->{'field'}});
		@val = values (%{$data->{'field'}});

		while(@keys){
			$num = pop(@val);
			$keyname = pop(@keys);
		@k[$num]= $keyname;
		}
This way the Key and the Value will be in the correct position of the
array.  IE if Data->Field->ElapsedTime = array position 2.
Please let me know.

Thanks in advance.



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

Date: Tue, 25 Sep 2007 15:34:10 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: get Hash of Array
Message-Id: <250920071534104844%jgibson@mail.arc.nasa.gov>

In article <1190749655.935172.183780@g4g2000hsf.googlegroups.com>, ebm
<ebmarquez@gmail.com> wrote:

> is there an easier way to capture the values from a hash of an array?
> here's what %data looks like if I use Dumper
> ---------------------------------------------------
> %data using Dumper
> $VAR1 = bless( {
>                  'fnames' => [
>                                'OwnerID',
>                                'FaxDateTime',
>                                'ElapsedTime',
>                                'Pages'
>                              ],
>                  'field' => {
>                               'ElapsedTime' => 2,
>                               'OwnerID' => 0,
>                               'Pages' => 3,
>                               'FaxDateTime' => 1
>                             }
>                }
> );
> 
> ---------------------------------------------------------------
> 
>     @keys = keys(%{$data->{'field'}});
>     @val = values (%{$data->{'field'}});
> 
>     while(@keys){
>       $num = pop(@val);
>       $keyname = pop(@keys);
>     @k[$num]= $keyname;

If you put 'use strict;' at the beginning of your program, Perl will
tell why this line is in error.

>     }
> This way the Key and the Value will be in the correct position of the
> array.  IE if Data->Field->ElapsedTime = array position 2.
> Please let me know.

It is not clear from your description what you are trying to do or why.

Here is some simpler code that does the same thing (puts the keys of
the $data->{field} hash into the array k according to the numerical
values in the hash:

foreach my $key ( keys %{$data->{'field'}} ) {
  my $num = $data->{'field'}->{$key};
  $k[$num]= $key;
}

or simpler:

while( my($key,$num) = each %{$data->{'field'}} ) {
  $k[$num]= $key;
}

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Wed, 26 Sep 2007 00:22:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: get Hash of Array
Message-Id: <6qhos4-ad9.ln1@osiris.mauzo.dyndns.org>


Quoth ebm <ebmarquez@gmail.com>:
> 
> 		@keys = keys(%{$data->{'field'}});
> 		@val = values (%{$data->{'field'}});
> 
> 		while(@keys){
> 			$num = pop(@val);
> 			$keyname = pop(@keys);
> 		@k[$num]= $keyname;
> 		}

    my @k;
    my $field = $data->{field};
    @k[values %$field] = keys %$field;

Ben



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

Date: Tue, 25 Sep 2007 14:40:22 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: how to make a runnable module (or modular script) ?
Message-Id: <13fi3u7ef6u3dcd@corp.supernews.com>

bugbear wrote:
> 
> Suggestions welcomed.

And supplied!

Thanks to all, for two, not one, but TWO
good solutions.

   BugBear


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

Date: Tue, 25 Sep 2007 12:18:33 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: how to make a runnable module (or modular script) ?
Message-Id: <250920071218333843%brian.d.foy@gmail.com>

In article <13fi3u7ef6u3dcd@corp.supernews.com>, bugbear
<bugbear@trim_papermule.co.uk_trim> wrote:


> Thanks to all, for two, not one, but TWO
> good solutions.

Well, two solutions, and one of them not good. The do( '' ) solution
has some gotchas, as mentioned in its documentation in perlfunc. The
error checking for do( '' ) involves both $! and $@, and now your
solution lives in two files instead of one.


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

Date: Wed, 26 Sep 2007 10:49:51 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: how to make a runnable module (or modular script) ?
Message-Id: <13fkapvpijqp1d9@corp.supernews.com>

brian d foy wrote:
> In article <13fi3u7ef6u3dcd@corp.supernews.com>, bugbear
> <bugbear@trim_papermule.co.uk_trim> wrote:
> 
> 
>> Thanks to all, for two, not one, but TWO
>> good solutions.
> 
> Well, two solutions, and one of them not good. The do( '' ) solution
> has some gotchas, as mentioned in its documentation in perlfunc. The
> error checking for do( '' ) involves both $! and $@, and now your
> solution lives in two files instead of one.

Of course it does - the "dispatcher" is one file,
and each "handler" is a normal runnable perl file.

The do solution has the merit that it can
be wrapped over a pre-existing script,
either legacy, or written by someone unaware
of the dispatcher.

Your solution is tidier, but more intrusive.

    BugBear


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

Date: Tue, 25 Sep 2007 11:31:56 -0700
From:  mike <needpassion@gmail.com>
Subject: How to read and write a file without open file twice? Thanks in advance.
Message-Id: <1190745116.704562.157250@57g2000hsv.googlegroups.com>

I'd like to code a function that performs read and write a file. The
file is for recording serial no, just a number inside. Each time when
the function is called, the file will be opened, locked, read,
increase the serial no, write, unlocked and closed, then return the
serial no in the end.

Is it possible to do the read and write operations in one file-open
with file lock?  Thanks in advance



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

Date: Tue, 25 Sep 2007 19:52:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to read and write a file without open file twice? Thanks in advance.
Message-Id: <sv1os4-566.ln1@osiris.mauzo.dyndns.org>


Quoth mike <needpassion@gmail.com>:
> I'd like to code a function that performs read and write a file. The
> file is for recording serial no, just a number inside.

perldoc -q increment

Ben



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

Date: Tue, 25 Sep 2007 18:51:27 -0700
From:  Ron Bergin <rkb@i.frys.com>
Subject: Re: How to read and write a file without open file twice? Thanks in advance.
Message-Id: <1190771487.150592.80640@57g2000hsv.googlegroups.com>

On Sep 25, 11:31 am, mike <needpass...@gmail.com> wrote:
> I'd like to code a function that performs read and write a file. The
> file is for recording serial no, just a number inside. Each time when
> the function is called, the file will be opened, locked, read,
> increase the serial no, write, unlocked and closed, then return the
> serial no in the end.
>
> Is it possible to do the read and write operations in one file-open
> with file lock?  Thanks in advance

use File::CounterFile;
http://search.cpan.org/~gaas/File-CounterFile-1.04/CounterFile.pm



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

Date: Tue, 25 Sep 2007 20:03:37 -0000
From:  bmw108@gmail.com
Subject: How to set a COM Object property to TRUE
Message-Id: <1190750617.818745.277630@g4g2000hsf.googlegroups.com>

Hello,

I am trying to set a WIN32 COM Object bool property true to enable a
validation option.

I can do it in VB like so.

emailPtr.CorrectSyntax = True

How do I do it in PERL?

I have tried so many different things to no avail.

$emailObj->{MxLookup} = (TRUE);
$emailObj->{MxLookup} = $TRUE;
$emailObj->{MxLookup} = 1;
$emailObj->{MxLookup} = TRUE;

Can anyone help?



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

Date: Tue, 25 Sep 2007 21:32:06 -0400
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: How to set a COM Object property to TRUE
Message-Id: <46f9b629$0$32518$4c368faf@roadrunner.com>

bmw108@gmail.com wrote:
> Hello,
> 
> I am trying to set a WIN32 COM Object bool property true to enable a
> validation option.
> 
> I can do it in VB like so.
> 
> emailPtr.CorrectSyntax = True
> 
> How do I do it in PERL?
> 
> I have tried so many different things to no avail.
> 
> $emailObj->{MxLookup} = (TRUE);
> $emailObj->{MxLookup} = $TRUE;
> $emailObj->{MxLookup} = 1;
> $emailObj->{MxLookup} = TRUE;
> 
> Can anyone help?

Maybe [untested]:

    $emailObj->{MxLookup} = -1;

?
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 26 Sep 2007 08:03:32 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: how to show the fragment of element from array ?
Message-Id: <46fa1254$0$8412$db0fefd9@news.zen.co.uk>

On Tue, 25 Sep 2007 00:33:24 -0700, esska@wp.pl <esska@wp.pl> wrote:
>  Hi all,
>  I have problem with 3-dimensional array:
>  push(@array,"$a,$b,$c");
>  I don't know how to show only $a from first element of this array.
>  Anyone could who knows answer, I will be grateful.

You are storing $a, $b and $c in a string. This is not the best
approach if you're just trying to store those values and retrieve them
later.

Better would be to store them in an (anonymous) array:

    push @array,  [ $a, $b, $c ];

    print $array[0][0], $array[0][2]; # gives $a & $c from the first
				      # element of the arrray

or use an (anonymous) hash:

    push @array, { a => $a, b => $b, c => $c };

    print $array[0]{a}, $array[0]{c} # gives $a & $c from the first
				     # element of the array




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

Date: Tue, 25 Sep 2007 11:32:49 -0700
From:  neurocline@gmail.com
Subject: Re: import fails if package namespace != module path
Message-Id: <1190745169.618956.125630@n39g2000hsh.googlegroups.com>

> Your use statement tries to call:
> Extra::Bits::Name->import(qw(func))

and

>     use Module ARGS;
>
> is exactly equivalent to
>
>     BEGIN {
>         require Module;
>         Module->import(ARGS);
>     }

Thanks. I knew that at one level, but I wasn't thinking it through.
Xho called it out clearly enough that it penetrated my skull. I wonder
if I can make extra import routines above and beyond the one Exporter
makes.

One reason I was playing with use vs package names is that I'm trying
to make self-installing modules (through a code reference pushed into
@INC that's just a few lines of HTTP fetch), and so I want my modules
to have a unique namespace so I can distinguish them from internal
ones. And I don't want to through all the code and edit their uses of
names.

Thanks for the help, I'm going to try a few things out.



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

Date: Wed, 26 Sep 2007 04:42:14 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Sep 26 2007
Message-Id: <JoyL2E.19s7@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

C-Scan-Constants-1.015
http://search.cpan.org/~icerider/C-Scan-Constants-1.015/
Slurp constants from specified C header (.h) files 
----
CPAN-Testers-Report-0.01
http://search.cpan.org/~fhoxh/CPAN-Testers-Report-0.01/
Creates CPAN Testers test-report objects 
----
Catalyst-Plugin-Unicode-0.8
http://search.cpan.org/~jrockway/Catalyst-Plugin-Unicode-0.8/
Unicode aware Catalyst 
----
Class-Workflow-0.07
http://search.cpan.org/~nuffin/Class-Workflow-0.07/
Light weight workflow system. 
----
ClearCase-SyncTree-0.40
http://search.cpan.org/~dsb/ClearCase-SyncTree-0.40/
Synchronize a tree of files with a tree of elements 
----
Config-Grammar-1.10
http://search.cpan.org/~dschwei/Config-Grammar-1.10/
A grammar-based, user-friendly config parser 
----
Crypt-SMIME-0.08
http://search.cpan.org/~mikage/Crypt-SMIME-0.08/
S/MIME message signing, verification, encryption and decryption 1 
----
File-pushd-1.00
http://search.cpan.org/~dagolden/File-pushd-1.00/
change directory temporarily for a limited scope 
----
HTML-Tiny-0.902
http://search.cpan.org/~andya/HTML-Tiny-0.902/
Lightweight, dependency free HTML/XML generation 
----
HTML-WikiConverter-Kwiki-0.51
http://search.cpan.org/~diberri/HTML-WikiConverter-Kwiki-0.51/
Convert HTML to Kwiki markup 
----
LaTeX-Driver-0.05
http://search.cpan.org/~andrewf/LaTeX-Driver-0.05/
Latex driver 
----
MIME-tools-5.422
http://search.cpan.org/~doneill/MIME-tools-5.422/
----
Mail-Box-2.075
http://search.cpan.org/~markov/Mail-Box-2.075/
manage a mailbox, a folder with messages 
----
MailTools-2.00_03
http://search.cpan.org/~markov/MailTools-2.00_03/
----
Net-SNMP-Vendor-0.01a
http://search.cpan.org/~endler/Net-SNMP-Vendor-0.01a/
lookup the Vendor for a sysObjectID based on the IANA list 
----
POE-Component-EasyDBI-1.23
http://search.cpan.org/~xantus/POE-Component-EasyDBI-1.23/
Perl extension for asynchronous non-blocking DBI calls in POE 
----
Parse-RPN-2.38
http://search.cpan.org/~fdulau/Parse-RPN-2.38/
----
PlotCalendar-1.3
http://search.cpan.org/~ajackson/PlotCalendar-1.3/
----
PowerTools-Data-0.02
http://search.cpan.org/~gbshouse/PowerTools-Data-0.02/
Additional Perl tool for Apache::ASP - MySQL database connection 
----
PowerTools-Data-0.03
http://search.cpan.org/~gbshouse/PowerTools-Data-0.03/
Additional Perl tool for Apache::ASP - MySQL database connection 
----
SQL-Loader-0.02
http://search.cpan.org/~benh/SQL-Loader-0.02/
----
TL1ng-0.01
http://search.cpan.org/~sscaffidi/TL1ng-0.01/
A simple, flexible, OO way to work with TL1. 
----
Template-Plugin-Latex-3.0001
http://search.cpan.org/~andrewf/Template-Plugin-Latex-3.0001/
Template Toolkit plugin for Latex 
----
Test-OpenID-Server-0.02
http://search.cpan.org/~jesse/Test-OpenID-Server-0.02/
setup a simulated OpenID server 
----
WWW-Mechanize-Plugin-AutoWrite-0.02
http://search.cpan.org/~jkutej/WWW-Mechanize-Plugin-AutoWrite-0.02/
WWW::Mechanize plugin to automaticaly write fetched page content to a file 
----
WebService-FogBugz-0.0.1
http://search.cpan.org/~shigeta/WebService-FogBugz-0.0.1/
Perl interface to the FogBugz API 
----
Workflow-0.30
http://search.cpan.org/~jonasbn/Workflow-0.30/
Simple, flexible system to implement workflows 
----
XML-LibXML-1.65
http://search.cpan.org/~pajas/XML-LibXML-1.65/
Perl Binding for libxml2 
----
constant-1.11
http://search.cpan.org/~saper/constant-1.11/
Perl pragma to declare constants 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

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


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

Date: Tue, 25 Sep 2007 18:45:41 -0700
From:  Matthew Cline <khym.chanur@gmail.com>
Subject: Upgrading Bundle::CPAN freezes during tests
Message-Id: <1190771141.712764.200650@19g2000hsx.googlegroups.com>

While using "perl -MCPAN -eshell" to install some Perl packages, I was
told that there was a new version of CPAN that I could upgrade to.  I
try to upgrade, and everything goes fine until it gets to the tests:

  /usr/bin/make  -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl5.8.8 "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00signature.......ok
        1/1 skipped: various reasons
t/01loadme..........ok
t/02nox.............ok
t/03pkgs............ok 1/11

And it just freezes at "t/03pkgs............ok 1/11".  It's not using
up any CPU, so it's not an infinite loop, but other than that I have
no clue.  I'm using perl 5.8.8

Thanks in advance.



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

Date: Wed, 26 Sep 2007 04:49:19 +0200
From: Daniel =?UTF-8?B?RMO8bmtlcg==?= <dduenker@uni-koblenz.de>
Subject: why are references so slow ?
Message-Id: <20070926044919.3b257be3.dduenker@uni-koblenz.de>

I have a script, with lots of deep recursion and noticed, that with the usage of references the whole programm becomes *much* slower (i noticed that in an earlier state, when i wanted to put something often used into a sub. The programm took at first less than 1 second, after i created the sub it took more than 5 seconds to complete.)
Now i am at a point where i want to use recursion, and perl says its even a deep recursion.
So, should i throw away all the parameters and just use global variables to get rid of referencing and dereferencing ?


-- 
Daniel Dünker <dduenker@uni-koblenz.de>


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

Date: Wed, 26 Sep 2007 00:26:57 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: why are references so slow ?
Message-Id: <260920070026575589%brian.d.foy@gmail.com>

In article <20070926044919.3b257be3.dduenker@uni-koblenz.de>, Daniel
Dˆºnker <dduenker@uni-koblenz.de> wrote:

> I have a script, with lots of deep recursion and noticed, that with the usage
> of references the whole programm becomes *much* slower (i noticed that in an
> earlier state, when i wanted to put something often used into a sub. The
> programm took at first less than 1 second, after i created the sub it took
> more than 5 seconds to complete.)
> Now i am at a point where i want to use recursion, and perl says its even a
> deep recursion.
> So, should i throw away all the parameters and just use global variables to
> get rid of referencing and dereferencing ?

Well, before you do anything, profile the application to see where the
slow parts really are. I would be surprised if it's the references, and
surprised if you haven't coded something that's an inefficient
algorithm (especially since you noted a deep recursion warning).

I talk about profiling in chapter 5, "Profiling", of Mastering Perl:

http://www252.pair.com/comdog/mastering_perl/Chapters/

Good luck :)


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

Date: Wed, 26 Sep 2007 09:03:58 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: why are references so slow ?
Message-Id: <1190797438.974344.94220@g4g2000hsf.googlegroups.com>

On Sep 26, 3:49 am, Daniel D=FCnker <dduen...@uni-koblenz.de> wrote:
> I have a script, with lots of deep recursion and noticed, that with the u=
sage of
> references the whole programm becomes *much* slower (i noticed that in an
> earlier state, when i wanted to put something often used into a sub. The =
programm
> took at first less than 1 second, after i created the sub it took more th=
an 5 seconds to
> complete.)

I'm not sure what this has to do with references but subroutine
calling it expensive in Perl. As are constructing and unpacking
argument lists.

> Now i am at a point where i want to use recursion, and perl says its even=
 a deep
> recursion.

If you want to use recursion I don't think you can do it without
subroutines. You'd have to refactor your code to be iterative.

> So, should i throw away all the parameters and just use global variables =
to get rid
> of referencing and dereferencing ?

I think it would have been clearer if you'd given us an example but if
I've understood correctly you effectively have a bunch of variables
that you are just passing unchanged down the recursion. Yes I'd
replace these by variables that are by some definition "globals". That
is to say they are used inside a subroutine but are not passed as
arguments. There are two obvious ways to go about this...

# Original

sub foo {
    my ($this,$that,$other) =3D @_;
    # stuff using $this,$that,$other...
    #  ...but not changing $this or $that
    foo ($this, $that, whatever);
    # stuff...
}
######################################

# With closure
sub foo {
    my ($this,$that,$other) =3D @_;
    my $r;
    $r =3D sub{
       my ($other) =3D @_;
       # stuff using $this,$that,$other...
       $r->(whatever);
       # stuff...
    };
    $r->($other);
    undef $r; # break circular reference
}
####################################

# With package variables and local()

our ($this,$that);

sub r {
       my ($other) =3D @_;
       # stuff using $this,$that,$other...
       $r->(whatever);
       # stuff...
}

sub foo {
    (local($this,$that),my ($other)) =3D @_;
    r($other);
}




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

Date: Wed, 26 Sep 2007 11:08:18 +0200
From: Daniel =?UTF-8?B?RMO8bmtlcg==?= <dduenker@uni-koblenz.de>
Subject: Re: why are references so slow ?
Message-Id: <20070926110818.0cb56f4f.dduenker@uni-koblenz.de>

On Wed, 26 Sep 2007 00:26:57 -0500
brian d  foy <brian.d.foy@gmail.com> wrote:

> In article <20070926044919.3b257be3.dduenker@uni-koblenz.de>, Daniel
> Dˆºnker <dduenker@uni-koblenz.de> wrote:
> 
> > I have a script, with lots of deep recursion and noticed, that with the usage
> > of references the whole programm becomes *much* slower (i noticed that in an
> > earlier state, when i wanted to put something often used into a sub. The
> > programm took at first less than 1 second, after i created the sub it took
> > more than 5 seconds to complete.)
> > Now i am at a point where i want to use recursion, and perl says its even a
> > deep recursion.
> > So, should i throw away all the parameters and just use global variables to
> > get rid of referencing and dereferencing ?
> 
> Well, before you do anything, profile the application to see where the
> slow parts really are. I would be surprised if it's the references, and
> surprised if you haven't coded something that's an inefficient
> algorithm (especially since you noted a deep recursion warning).
> 
> I talk about profiling in chapter 5, "Profiling", of Mastering Perl:
> 
> http://www252.pair.com/comdog/mastering_perl/Chapters/
> 
> Good luck :)

Wow thanks, that's a very interesting tool, and of course you are right, there are still lot's of inefficient things in my script, but it seems that the slowest part's are actually really referencing and dereferencing, as for example:
     4455   3.53946   3.40000   133: return \%pixels;
which is the part that takes the most time.

-- 
Daniel Dünker <dduenker@uni-koblenz.de>


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

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


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