[28180] in Perl-Users-Digest
Perl-Users Digest, Issue: 9544 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 1 14:05:58 2006
Date: Tue, 1 Aug 2006 11:05:09 -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 Tue, 1 Aug 2006 Volume: 10 Number: 9544
Today's topics:
Re: foreach aliasing, my variables, and visibility in s <benmorrow@tiscali.co.uk>
Re: How to control PDF printer <rafalk@comcast.net>
Re: odd crash in file upload via CGI <msoulier@gmail.com>
perl_parse and multi threading lililevy@hotmail.com
Please Help! VJDIVINE@gmail.com
Re: Please Help! <bik.mido@tiscalinet.it>
Re: Please Help! <benmorrow@tiscali.co.uk>
print command <ray_lokey7543@yahoo.com>
Re: print command <bik.mido@tiscalinet.it>
Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <jurgenex@hotmail.com>
Re: Recursion <bugbear@trim_papermule.co.uk_trim>
Re: Recursion xhoster@gmail.com
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <David.Squire@no.spam.from.here.au>
Re: Recursion <uri@stemsystems.com>
Re: Recursion <mritty@gmail.com>
Re: Recursion xhoster@gmail.com
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <koko_loko_0@yahoo.co.uk>
Unicode and Perl <bill@ts1000.us>
Re: Unicode and Perl <anfi@onet.eu>
Re: Unicode and Perl <jurgenex@hotmail.com>
Re: Unicode and Perl <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Using an input/csv file to rename files <tdcarr@gmail.com>
Re: Using an input/csv file to rename files <tzz@lifelogs.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 1 Aug 2006 15:57:42 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <6o64q3-qlt.ln1@osiris.mauzo.dyndns.org>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Tue, 01 Aug 2006 06:12:41 GMT, "register_allocation"
> <register_allocation@lycos.com> wrote:
>
> >my $v = '???';
> >foreach $v ('foo') {
> > print "in loop, \$v=$v\n";
> > process();
> >}
> >sub process { print "in process, \$v=$v\n" }
> >
> >__END__
> >This prints
> >in loop, $v=foo
> >in process, $v=???
> [snip]
> >Is this a known thing? Bug? Feature?
> ^^^^^^^
> ^^^^^^^
>
> process() is a closure around the variable $v lexically declared in
> the sorrounding scope.
No it's not. Named subs are not closures in Perl5. It's just in a
different scope from the body of the for loop, with a different
variable named '$v'. Compare with C:
void
foo(void)
{
char *v = "???";
{
char *v = "foo";
printf("%s\n", v);
}
printf("%s\n", v);
}
No closures at all in C, but the same behaviour. The only slightly odd
thing is that if $v is a 'my' variable then 'for $v (...)' implicitly
re-'my's it.
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
benmorrow@tiscali.co.uk Frank Herbert, 'Dune'
------------------------------
Date: Tue, 01 Aug 2006 07:00:34 -0400
From: Rafal Konopka <rafalk@comcast.net>
Subject: Re: How to control PDF printer
Message-Id: <cvcuc2h4sbmiv9t5qigvteb4mv3p9der3s@4ax.com>
On Sat, 29 Jul 2006 19:10:55 GMT, "Bill Segraves"
<segraves_f13@mindspring.com> wrote:
><rafalk@comcast.net> wrote in message
>news:qbjmc21gdgbl31o7t6pgboo4fsvj730553@4ax.com...
>> Q: How can I control thses Adobe PDF settings with perl?
><snip>
>> It works! However, I'd prefer to be able to control these attributes
>> dynamically, either from inside the script or even with a separate
>> pre-processing script.
>>
>> Q: How can I control thses Adobe PDF settings with perl?
>
>You might try a Google Groups search with "cameron dorey win32::ole acrobat"
>to see a relevant contribution by Prof. Cameron Dorey.
Thanks, this is exactly what I'm doing. However, it requires manual
setting of PDF printer attributes. I was wondering if anyone used
Perl to set these attributes dynamically.
Rafal
------------------------------
Date: 1 Aug 2006 09:05:11 -0700
From: "msoulier" <msoulier@gmail.com>
Subject: Re: odd crash in file upload via CGI
Message-Id: <1154448310.940744.168810@m73g2000cwd.googlegroups.com>
Charles DeRykus wrote:
> Is the version discrepancy between 5.8.5 and 5.8.0 expected... Could
> your environment be picking up older installs...
I don't believe so, but I suppose I should ask the CentOS people, and
the owner of the Dag repository. I believe that's where the code is
coming from.
Mike
------------------------------
Date: 1 Aug 2006 06:09:29 -0700
From: lililevy@hotmail.com
Subject: perl_parse and multi threading
Message-Id: <1154437769.322886.236250@b28g2000cwb.googlegroups.com>
Hello,
I would very much appreciate your answers on the following issue.
I have a multi threaded application. Each thread is running a function
that creates a perl interpreter and uses it to parse and then run a
perl function from an arbitrary file.
After running this application for a while I'm having a deadlock and
I can see that 10 threads are in the perl_parse function.
I'm running on WInXP with perl 5.8.3.809.
Are any of you are familiar with such a problem? Do you have an idea
why this can happen?
I've attached my function code and marked the line where the threads
are "stuck":
__declspec(dllexport)
long CFTPerlUserExitInstanceRun(char *FileName,char *FuncName,struct
PerlParmInfo *ParmsVec,unsigned int ParmsVecSize,char* pReason,int
*pCount,int *pUserExitRc)
{
long lRc = 0;
int count = -1;
PerlInterpreter* my_perl = NULL;
char *embedding[] = { "", FileName};
while (true)
{
my_perl = perl_alloc();
if (my_perl == NULL)
{
lRc = -1;
break;
}
EnterCriticalSection(&g_ParserCS);
PERL_SET_CONTEXT(my_perl);
PL_perl_destruct_level = 1;
perl_construct(my_perl);
LeaveCriticalSection(&g_ParserCS);
// *****************************************************
// THREADS ARE STUCK IN PERL_PARSE
// *****************************************************
lRc = perl_parse(my_perl, xs_init, 2, embedding , NULL);
if (lRc != 0)
{
lRc = -2;
break;
}
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// push parms to stack
char ParmType[MAX_PARM_TYPE_LEN];
for(unsigned int i=0; i<ParmsVecSize; i++)
{
strncpy(ParmType, PERL_WRAP_PACKAGE_NAME,
MAX_PARM_TYPE_LEN-1);
strncat(ParmType, "::", MAX_PARM_TYPE_LEN-3);
strncat(ParmType, ParmsVec[i].parmtype, MAX_PARM_TYPE_LEN-
strlen(PERL_WRAP_PACKAGE_NAME)-3);
SV *pSVParm = sv_newmortal();
sv_setref_pv( pSVParm, ParmType, ParmsVec[i].parm );
XPUSHs(pSVParm);
}
PUTBACK;
try
{
count = call_pv(FuncName, G_EVAL|G_SCALAR);
}
catch(...)
{
lRc = -3;
}
SPAGAIN;
// Check the eval first
if (SvTRUE(ERRSV))
{
STRLEN n_a;
strncpy(pReason, SvPV(ERRSV, n_a), MAX_PERL_REASON_LENGTH-1);
//@G1028
lRc = -4;
POPs ;
}
else
{
if (count != 1)
{
*pCount = count;
lRc = -5;
}
else
{
*pUserExitRc = POPi;
}
}
PUTBACK ;
FREETMPS ;
LEAVE ;
break;
}
if (my_perl != NULL)
{
EnterCriticalSection(&g_ParserCS);
PL_perl_destruct_level = 1;
perl_destruct(my_perl);
LeaveCriticalSection(&g_ParserCS);
perl_free(my_perl);
}
return lRc;
}
Thank you very much.
Lily.
------------------------------
Date: 1 Aug 2006 05:03:17 -0700
From: VJDIVINE@gmail.com
Subject: Please Help!
Message-Id: <1154433797.449861.220520@b28g2000cwb.googlegroups.com>
I need to catch an error printed by a module that I use. the problem
with this module is apart from using a log it also prints certain
errors directly to STDERR.
I want to catch these errors being printed to STDERR and log it into my
own logfile.
Since this module is an API I cannot change it's log config.
How to use eval and $SIG{__WARN__} to workaround this problem ? Or are
there any other solutions ?
Kindly guide me on this,
Thanks,
VJ
------------------------------
Date: 1 Aug 2006 16:00:35 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Please Help!
Message-Id: <9jnuc21af5880oi2i26rfl2vihocsoka8k@4ax.com>
On 1 Aug 2006 05:03:17 -0700, VJDIVINE@gmail.com wrote:
>Subject: Please Help!
Yes, I do help!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 1 Aug 2006 16:03:25 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Please Help!
Message-Id: <t274q3-qlt.ln1@osiris.mauzo.dyndns.org>
Quoth VJDIVINE@gmail.com:
> I need to catch an error printed by a module that I use. the problem
> with this module is apart from using a log it also prints certain
> errors directly to STDERR.
> I want to catch these errors being printed to STDERR and log it into my
> own logfile.
>
> Since this module is an API I cannot change it's log config.
>
> How to use eval and $SIG{__WARN__} to workaround this problem ?
If it is really printing directly to STDERR then you can't. If it uses
warn/die then you can use $SIG{__WARN__}/eval to catch the errors, but
you already knew that so I presume it isn't :).
> Or are
> there any other solutions ?
Open STDERR onto a string, like this:
my $STDERR_LOG;
open STDERR, '>', \$STDERR_LOG or die "can't catch STDERR: $!";
Note this requires 5.6(.1?) to work right.
Anything printed to STDERR will go into that string. You may want to dup
stderr somewhere else first, so's you can put it back afterwards.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
benmorrow@tiscali.co.uk
------------------------------
Date: 1 Aug 2006 06:24:28 -0700
From: "ray" <ray_lokey7543@yahoo.com>
Subject: print command
Message-Id: <1154438668.237108.12360@m79g2000cwm.googlegroups.com>
Trying to substitute /bar/ for /foo/ and write the result of the
substitution to a file:
Both of commands are not correct syntactically, missing something or
not possible to print the result from a command ?
perl -pi -e 's/\bbar\b/foo/g' `find . -type f` -print 0| xargs -0
perl -pi -e -print 0| xargs -0 's/\bbar\b/foo/g' `find . -type f`
Please help me.
------------------------------
Date: 1 Aug 2006 16:11:54 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: print command
Message-Id: <amnuc2pkust5dvvccli2t3aogm1m1qscu9@4ax.com>
On 1 Aug 2006 06:24:28 -0700, "ray" <ray_lokey7543@yahoo.com> wrote:
>perl -pi -e 's/\bbar\b/foo/g' `find . -type f` -print 0| xargs -0
Not a perl problem: you want a list of arguments to the perl command,
which in itself is fine. if your filenames are not too exhotic the
following should suffice
perl -pi -e 's/\bbar\b/foo/g' $(find . -type f)
(I don't like backticks either in shell or in perl)
otherwise
find . -type f -print 0| xargs -0 perl -pi -e 's/\bbar\b/foo/g'
>perl -pi -e -print 0| xargs -0 's/\bbar\b/foo/g' `find . -type f`
Huh?!? This looks like a random shuffle of the correct command,
whatever it may be. 's/\bbar\b/foo/g' must be an argument to perl's
-e, to which you give '-print' instead: althoug syntactically valid,
the latter won't do much... OTOH you're telling xargs to call the
s/\bbar\b/foo/g program: do you really have such a beast in your
path?!?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 1 Aug 2006 16:28:42 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Recursion
Message-Id: <eanrva$7l9$1@news.al.sw.ericsson.se>
Hi all.
I know Perl is not the best choice for resursive function calls but I wanted
to write a quicksort in Perl.
I used Memoize module to help me do it but I still get errors like:
_____________________________________________________________________
Deep recursion on anonymous subroutine at QuickSort.pl line 40, <STDIN> line
1.
Deep recursion on subroutine "Memoize::_memoizer" at (eval 2) line 1,
<STDIN> line 1.
Deep recursion on subroutine "main::qs" at C:/Perl/lib/Memoize.pm line 269,
<STDIN> line 1.
________________________________________________________________________
This happens when the array to be sorted has more than 60k elements and only
when run under Windows.
And I'm not very happy with the speed either, I hoped it would be way
faster.
Any help? The code 's below.
Thx
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------------
#!/usr/bin/perl -w
use strict;
use Memoize;
memoize ('qs');
my @array;
my $size;
print "Enter the number of elements to be sorted: \n";
chomp($size = <STDIN>);
foreach (1..$size) {push @array, int(rand(1000))}
my $start = time();
@array = &qs(@array);
my $finish = time();
#print "The sorted array is:\n @array \n";
print "The array of $size elements QuickSorted in ",$finish - $start,"
seconds \n";
sub qs {
my @array = @_;
my $pivot = $#array;
my @smaller_numbers;
my @larger_numbers;
my $i;
for ($i=0;$i<$pivot;$i++){
if ($array[$i] <= $array[$pivot]){
unshift @smaller_numbers, $array[$i]
}
else{
push @larger_numbers, $array[$i]
}
}
if ($#smaller_numbers > 0){@smaller_numbers = &qs(@smaller_numbers)}
if ($#larger_numbers > 0) {@larger_numbers = &qs(@larger_numbers)}
push @smaller_numbers,($array[$pivot],@larger_numbers);
return @smaller_numbers;
}
------------------------------
Date: Tue, 01 Aug 2006 15:34:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Recursion
Message-Id: <SvKzg.7531$oz.7270@trnddc07>
kokolo wrote:
> I know Perl is not the best choice for resursive function calls
I am curious why. Mind to explain?
jue
------------------------------
Date: Tue, 01 Aug 2006 16:32:58 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Recursion
Message-Id: <44cf742a$0$69361$ed2619ec@ptn-nntp-reader01.plus.net>
kokolo wrote:
> Hi all.
>
> I know Perl is not the best choice for resursive function calls but I wanted
> to write a quicksort in Perl.
> I used Memoize module to help me do it but I still get errors like:
> _____________________________________________________________________
> Deep recursion on anonymous subroutine at QuickSort.pl line 40, <STDIN> line
> 1.
> Deep recursion on subroutine "Memoize::_memoizer" at (eval 2) line 1,
> <STDIN> line 1.
> Deep recursion on subroutine "main::qs" at C:/Perl/lib/Memoize.pm line 269,
> <STDIN> line 1.
> ________________________________________________________________________
>
> This happens when the array to be sorted has more than 60k elements and only
> when run under Windows.
> And I'm not very happy with the speed either, I hoped it would be way
> faster.
Try passing arrays and sub array by reference, not value.
BugBear
------------------------------
Date: 01 Aug 2006 15:40:41 GMT
From: xhoster@gmail.com
Subject: Re: Recursion
Message-Id: <20060801114830.730$vS@newsreader.com>
"kokolo" <koko_loko_0@yahoo.co.uk> wrote:
> Hi all.
>
> I know Perl is not the best choice for resursive function calls
Why?
> but I
> wanted to write a quicksort in Perl.
Why?
> I used Memoize module to help me do it
Why!?
> but I still get errors like:
> _____________________________________________________________________
> Deep recursion on anonymous subroutine at QuickSort.pl line 40, <STDIN>
> line 1.
> Deep recursion on subroutine "Memoize::_memoizer" at (eval 2) line 1,
> <STDIN> line 1.
> Deep recursion on subroutine "main::qs" at C:/Perl/lib/Memoize.pm line
> 269, <STDIN> line 1.
> ________________________________________________________________________
Those aren't errors, those are warnings. perldoc perldiag will tell
what it means, and perldoc warnings will tell you how to turn them off.
> This happens when the array to be sorted has more than 60k elements and
> only when run under Windows.
> And I'm not very happy with the speed either, I hoped it would be way
> faster.
Way faster than what? Why do you care how fast it is? Perl has a built
in sort. Use it if you care about speed.
> #!/usr/bin/perl -w
>
> use strict;
> use Memoize;
>
> memoize ('qs');
What possible good could come from this?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 1 Aug 2006 17:18:23 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eanusk$8pp$1@news.al.sw.ericsson.se>
:)
Well, I asked for some help, not for a lecture :" Become a Perl expert and
only then ask a question"
<xhoster@gmail.com> wrote in message
news:20060801114830.730$vS@newsreader.com...
> "kokolo" <koko_loko_0@yahoo.co.uk> wrote:
> > Hi all.
> >
> > I know Perl is not the best choice for resursive function calls
>
> Why?
>
----I'll correct myself: " I read there are certain problems with recursive
functions in Perl unless properly taken care of"
I don't think I took a good care.
> > but I
> > wanted to write a quicksort in Perl.
>
> Why?
>
-------Because I'm curious and I wanted to see how I'll do.
> > I used Memoize module to help me do it
>
> Why!?
>
-----Because I read it helps with recursive calls and thought I could make
use of it. It looks to me it's not needed here.
> > but I still get errors like:
> > _____________________________________________________________________
> > Deep recursion on anonymous subroutine at QuickSort.pl line 40, <STDIN>
> > line 1.
> > Deep recursion on subroutine "Memoize::_memoizer" at (eval 2) line 1,
> > <STDIN> line 1.
> > Deep recursion on subroutine "main::qs" at C:/Perl/lib/Memoize.pm line
> > 269, <STDIN> line 1.
> > ________________________________________________________________________
>
> Those aren't errors, those are warnings. perldoc perldiag will tell
> what it means, and perldoc warnings will tell you how to turn them off.
>
>
-----I don't want to turn them off, thank you for telling me how to use
perldiag, now I know where the warnings came from.
> > This happens when the array to be sorted has more than 60k elements and
> > only when run under Windows.
> > And I'm not very happy with the speed either, I hoped it would be way
> > faster.
>
> Way faster than what? Why do you care how fast it is? Perl has a built
> in sort. Use it if you care about speed.
>
--- I wanted to compare it to other sorts I wrote to see how efficient it
is.
I care about making MY program better, even if there's a turbosort available
>
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use Memoize;
> >
> > memoize ('qs');
>
> What possible good could come from this?
>
>
> Xho
>
-- I can see now it's not needed either. Thank you, you improve my learning
curve :)
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 1 Aug 2006 17:32:59 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eanvnu$92v$1@news.al.sw.ericsson.se>
Can you advise me how to do it?
kokolo
"bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
news:44cf742a$0$69361$ed2619ec@ptn-nntp-reader01.plus.net...
> kokolo wrote:
> > Hi all.
> >
> > I know Perl is not the best choice for resursive function calls but I
wanted
> > to write a quicksort in Perl.
> > I used Memoize module to help me do it but I still get errors like:
> > _____________________________________________________________________
> > Deep recursion on anonymous subroutine at QuickSort.pl line 40, <STDIN>
line
> > 1.
> > Deep recursion on subroutine "Memoize::_memoizer" at (eval 2) line 1,
> > <STDIN> line 1.
> > Deep recursion on subroutine "main::qs" at C:/Perl/lib/Memoize.pm line
269,
> > <STDIN> line 1.
> > ________________________________________________________________________
> >
> > This happens when the array to be sorted has more than 60k elements and
only
> > when run under Windows.
> > And I'm not very happy with the speed either, I hoped it would be way
> > faster.
>
> Try passing arrays and sub array by reference, not value.
>
> BugBear
------------------------------
Date: Tue, 01 Aug 2006 17:51:28 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Recursion
Message-Id: <eao0qg$abg$1@gemini.csx.cam.ac.uk>
kokolo wrote:
[top-posting corrected. Please don't do that]
> "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
> news:44cf742a$0$69361$ed2619ec@ptn-nntp-reader01.plus.net...
>> kokolo wrote:
>>>
>>> This happens when the array to be sorted has more than 60k elements and
> only
>>> when run under Windows.
>>> And I'm not very happy with the speed either, I hoped it would be way
>>> faster.
>> Try passing arrays and sub array by reference, not value.
>>
> Can you advise me how to do it?
See perldoc perlsub, and search for "Pass by Reference". See also
perldoc -q 'how can i pass'
DS
------------------------------
Date: Tue, 01 Aug 2006 13:08:25 -0400
From: Uri Guttman <uri@stemsystems.com>
To: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <x764hcgz92.fsf@mail.sysarch.com>
>>>>> "k" == kokolo <koko_loko_0@yahoo.co.uk> writes:
>> > I used Memoize module to help me do it
>>
>> Why!?
>>
k> -----Because I read it helps with recursive calls and thought I could make
k> use of it. It looks to me it's not needed here.
sorting is NOT a recursive operation where the args are always the
same. memoize would help only on repeated calls with the same args but
quicksort will pass in different sets each time.
>> Way faster than what? Why do you care how fast it is? Perl has a built
>> in sort. Use it if you care about speed.
>>
k> --- I wanted to compare it to other sorts I wrote to see how efficient it
k> is.
k> I care about making MY program better, even if there's a turbosort
k> available
use Sort::Maker. you ain't gonna write something faster unless you are
deep into sorting algorithms. and it uses perl's sort function
underneath as well. you are barking up the wrong tree to write a sort
directly in perl as perl's overhead will kill the sorting vs. the c
speed of the builtin sort.
and using a sort module MAKES your program better. if you are writing a
quicksort to learn how to do it that is another story but you don't seem
to be doing that. if you can't cleanly implement a sort from a published
algorithm why do you think you can do it better than a module or perl's
built in sort? do you even know about O(N) notation to compare sort
speeds (or other algorithms)? you might also want to read my paper on
perl sorting or the docs of sort::maker to learn more about sorting in
perl.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 1 Aug 2006 10:12:10 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Recursion
Message-Id: <1154452330.326711.227630@i42g2000cwa.googlegroups.com>
kokolo wrote:
> Well, I asked for some help, not for a lecture :" Become a Perl expert and
> only then ask a question"
For maximum help from this newsgroup, improve your attitude in three
ways:
1) Stop being under the impression that anyone here has an obligation
to help you, or to give you exactly what you ask for. We're all
volunteers. If you want point-by-point specific help, hire a
consultant.
2) Stop rebuking a "lecture". Lectures are good things. They teach
you. They instruct you. They make you a better programmer. If
someone offers to tell you why or how you're doing something wrong
(whether that 'something' has to do with Perl or with your methodology
or with your Usenet postings), thank them.
3) Get over yourself. No one *ever* said that asking a question is
bad, or that you need to be an expert before you ask questions.
Questions are encouraged and welcomed. Badly formed, poorly
thought-out questions, on the other hand, are justifiably ignored,
flamed, and/or lectured against. Take the advice your given, write
better questions, and you'll do fine.
You should start by reading the Posting Guidelines for this group.
They are posted here twice a week, and contain invaluable information
about how you can maximize the usefulness of this group.
Paul Lalli
------------------------------
Date: 01 Aug 2006 17:30:00 GMT
From: xhoster@gmail.com
Subject: Re: Recursion
Message-Id: <20060801133749.970$os@newsreader.com>
"kokolo" <koko_loko_0@yahoo.co.uk> wrote:
> <xhoster@gmail.com> wrote in message
> news:20060801114830.730$vS@newsreader.com...
> > "kokolo" <koko_loko_0@yahoo.co.uk> wrote:
> > > Hi all.
> > >
> > > I know Perl is not the best choice for resursive function calls
> >
> > Why?
> >
> ----I'll correct myself: " I read there are certain problems with
> recursive functions in Perl unless properly taken care of"
Well, that is true of all languages (and I suppose of all topics, not
just recursion.)
> > > but I
> > > wanted to write a quicksort in Perl.
> >
> > Why?
> >
> -------Because I'm curious and I wanted to see how I'll do.
OK. But then you shouldn't be surprised if it is slow! That type
of thing is not what Perl was built for, which is why sorting is a Perl
primitive. It is something that is ubiquitous and cannot be well
implemented efficiently in pure Perl.
> >
> > Way faster than what? Why do you care how fast it is? Perl has a
> > built in sort. Use it if you care about speed.
> >
> --- I wanted to compare it to other sorts I wrote to see how efficient it
> is.
How did it do?
>
> I care about making MY program better,
I thought your care was learn stuff, rather than get a better sort in and
of itself?
Anyway, figure out where the time is going. I like SmallProf for things
like that. It looks like you spend most of your time copying data around,
which is not surprising as every recursive level moves every element twice
(once going, into the subarrays, and once coming out, to put them back in
big array.)
Pass the subroutine an arrayref to the entire dataset, plus a left and
right pointer to the part that this particular invocation is concerned
with. Parition, pretty much like you would in C. Pass the same arrayref,
plus the new pointers, to your recursive call.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 1 Aug 2006 18:45:30 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eao3vs$als$1@news.al.sw.ericsson.se>
I agree completely, I am a Perl beginner but not new to Usenet.
I just don't like arrogancy so I reacted.
"Paul Lalli" <mritty@gmail.com> wrote in message
news:1154452330.326711.227630@i42g2000cwa.googlegroups.com...
> kokolo wrote:
> > Well, I asked for some help, not for a lecture :" Become a Perl expert
and
> > only then ask a question"
>
> For maximum help from this newsgroup, improve your attitude in three
> ways:
> 1) Stop being under the impression that anyone here has an obligation
> to help you, or to give you exactly what you ask for. We're all
> volunteers. If you want point-by-point specific help, hire a
> consultant.
> 2) Stop rebuking a "lecture". Lectures are good things. They teach
> you. They instruct you. They make you a better programmer. If
> someone offers to tell you why or how you're doing something wrong
> (whether that 'something' has to do with Perl or with your methodology
> or with your Usenet postings), thank them.
> 3) Get over yourself. No one *ever* said that asking a question is
> bad, or that you need to be an expert before you ask questions.
> Questions are encouraged and welcomed. Badly formed, poorly
> thought-out questions, on the other hand, are justifiably ignored,
> flamed, and/or lectured against. Take the advice your given, write
> better questions, and you'll do fine.
>
> You should start by reading the Posting Guidelines for this group.
> They are posted here twice a week, and contain invaluable information
> about how you can maximize the usefulness of this group.
>
> Paul Lalli
>
------------------------------
Date: Tue, 1 Aug 2006 18:59:15 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eao4pl$b28$1@news.al.sw.ericsson.se>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x764hcgz92.fsf@mail.sysarch.com...
> >>>>> "k" == kokolo <koko_loko_0@yahoo.co.uk> writes:
>
> >> > I used Memoize module to help me do it
> >>
> >> Why!?
> >>
>
> k> -----Because I read it helps with recursive calls and thought I could
make
> k> use of it. It looks to me it's not needed here.
>
> sorting is NOT a recursive operation where the args are always the
> same. memoize would help only on repeated calls with the same args but
> quicksort will pass in different sets each time.
>
Got that with memoize.
> >> Way faster than what? Why do you care how fast it is? Perl has a
built
> >> in sort. Use it if you care about speed.
> >>
> k> --- I wanted to compare it to other sorts I wrote to see how
efficient it
> k> is.
>
> k> I care about making MY program better, even if there's a turbosort
> k> available
>
> use Sort::Maker. you ain't gonna write something faster unless you are
> deep into sorting algorithms. and it uses perl's sort function
> underneath as well. you are barking up the wrong tree to write a sort
> directly in perl as perl's overhead will kill the sorting vs. the c
> speed of the builtin sort.
>
I'm well aware of it, I was writing it just to see how to do it in Perl.
> and using a sort module MAKES your program better. if you are writing a
> quicksort to learn how to do it that is another story but you don't seem
> to be doing that. if you can't cleanly implement a sort from a published
> algorithm why do you think you can do it better than a module or perl's
> built in sort? do you even know about O(N) notation to compare sort
> speeds (or other algorithms)? you might also want to read my paper on
> perl sorting or the docs of sort::maker to learn more about sorting in
> perl.
>
> uri
>
I didn't have a slightest intention (that would be really ignorant!) on
writing anything that would be faster than any C implemented
quiscksort, or Perl's bulitin mergesort, or Radix sort, or any of other
C-like languages implemented O(NlogN) sorts,
I just wanted to write a quicksort in Perl and compare it to e.g.
Shellsort. I was curious how to write these sorting algorithms in Perl
as I'm learning Perl and thought algorithms would be interesting exercises.
I'm only wondering why it's not as fast as I expected it to be.
Thx,
kokolo
> --
> Uri Guttman ------ uri@stemsystems.com --------
http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and
Coding-
> Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org
------------------------------
Date: 1 Aug 2006 06:34:03 -0700
From: "Bill H" <bill@ts1000.us>
Subject: Unicode and Perl
Message-Id: <1154439243.406995.81870@s13g2000cwa.googlegroups.com>
I have a perl program that reads in text files and creates web pages
using the content of the text files. I now have to include text in
Russian in these text files so I need to save them as unicode. The
problem that arises is that my perl program can no longer read the
files due to the fact that all the text is in unicode, not just the
russian parts. Is there a way fixing the text so that only the unicode
parts are in unicode and the rest are in straight text.
Here is an example of what is bering read in:
QUESTIONS1=3D1. =D0=AF =D0=BF=D1=80=D0=B5=D0=B4=D0=BF=D0=BE=D1=87=D0=B8=D1=
=82=D0=B0=D1=8E =D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C =D1=87=D1=82=D0=BE-=D0=
=BB=D0=B8=D0=B1=D0=BE =D0=B2
=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B5
QUESTIONS2=3D2. I love learning new skills
QUESTIONS3=3D3. My word is my bond
QUESTIONS4=3D4. I like being the boss
I looked at the source of the unicode text and a null character (0) is
inserted before every non-unicode letter, is there a way of removing
these nulls?
Bill H
------------------------------
Date: Tue, 01 Aug 2006 15:50:55 +0200
From: Andrzej Adam Filip <anfi@onet.eu>
Subject: Re: Unicode and Perl
Message-Id: <873bcg4la8.fsf@anfi.homeunix.net>
"Bill H" <bill@ts1000.us> writes:
> I have a perl program that reads in text files and creates web pages
> using the content of the text files. I now have to include text in
> Russian in these text files so I need to save them as unicode. The
> problem that arises is that my perl program can no longer read the
> files due to the fact that all the text is in unicode, not just the
> russian parts. Is there a way fixing the text so that only the unicode
> parts are in unicode and the rest are in straight text.
>
> Here is an example of what is bering read in:
>
> QUESTIONS1=1. Я предпочитаю делать что-либо в
> группе
> QUESTIONS2=2. I love learning new skills
> QUESTIONS3=3. My word is my bond
> QUESTIONS4=4. I like being the boss
>
> I looked at the source of the unicode text and a null character (0) is
> inserted before every non-unicode letter, is there a way of removing
> these nulls?
1) Are you sure you created source files in UTF-8? [not UTF-16]
2) Have you tried to explicitly specify encoding of input and output files?
#v+
open(FILE, "<:utf8", $file_name)
#v-
See "man perlopentut" for more details
--
[pl2en: Andrew] Andrzej Adam Filip : anfi@priv.onet.pl : anfi@xl.wp.pl
------------------------------
Date: Tue, 01 Aug 2006 14:17:18 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Unicode and Perl
Message-Id: <OnJzg.6877$jt.3110@trnddc04>
Bill H wrote:
> I have a perl program that reads in text files and creates web pages
> using the content of the text files. I now have to include text in
> Russian in these text files so I need to save them as unicode.
Well, sort of.
- there are other character sets that allow multi-lingual text within the
same file. But Unicode is certainly a good choice
- "Unicode" text can be encoded in many different ways. Which one are you
talking about?
> The
> problem that arises is that my perl program can no longer read the
> files due to the fact that all the text is in unicode, not just the
> russian parts.
Well, yes, that's usually what happens. And it's the beauty of Unicode that
specifically you _don't_ have to encode each language in a different
character set because it covers them all (well, at least unless you are
going very exotic).
> Is there a way fixing the text so that only the unicode
> parts are in unicode and the rest are in straight text.
You are dealing with a language where the characters for this language are
not in Unicode? Not even in a surrogate set? I find this very hard to
believe to say the least.
> Here is an example of what is bering read in:
>
> QUESTIONS1=1. ? ??????????? ?????? ???-???? ?
> ??????
> QUESTIONS2=2. I love learning new skills
> QUESTIONS3=3. My word is my bond
> QUESTIONS4=4. I like being the boss
>
> I looked at the source of the unicode text and a null character (0) is
> inserted before every non-unicode letter, is there a way of removing
> these nulls?
There are no non-Unicode letters in your sample (or maybe my Newsreader
doesn't display them). It appears to me you have cyrillic and latin
characters and of course both are included in Unicode.
If there is really a null character before some other characters as you are
claiming then the software that generated the text is bogus.
Or are you talking about a null byte, maybe? Then chances are you saved your
file as UTF-16. Unfortunately you didn't show us any of your Perl code,
therefore there is no way for us to check if you are reading the file as
UTF-16, too. And as I mentioned at the very beginning, you are not telling
us which encoding you are using, either.
jue
------------------------------
Date: Tue, 01 Aug 2006 16:36:23 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Unicode and Perl
Message-Id: <bqLzg.8354$157.7450@newsread3.news.pas.earthlink.net>
On 08/01/2006 08:34 AM, Bill H wrote:
> I have a perl program that reads in text files and creates web pages
> using the content of the text files. I now have to include text in
> Russian in these text files so I need to save them as unicode. The
> problem that arises is that my perl program can no longer read the
> files due to the fact that all the text is in unicode, not just the
> russian parts. Is there a way fixing the text so that only the unicode
> parts are in unicode and the rest are in straight text.
>
> Here is an example of what is bering read in:
>
> QUESTIONS1=1. Я предпочитаю делать что-либо в
> группе
> QUESTIONS2=2. I love learning new skills
> QUESTIONS3=3. My word is my bond
> QUESTIONS4=4. I like being the boss
>
> I looked at the source of the unicode text and a null character (0) is
> inserted before every non-unicode letter, is there a way of removing
> these nulls?
>
> Bill H
>
What you posted is clearly utf-8, but nulls before each ascii
character suggest utf-16 (?). "Perldoc -f open" and "perldoc
perluniintro" and "perldoc Encode::Supported" will help you
figure out the right IO layer to use when reading those files.
------------------------------
Date: 1 Aug 2006 06:53:47 -0700
From: "Terry" <tdcarr@gmail.com>
Subject: Re: Using an input/csv file to rename files
Message-Id: <1154440427.124781.115450@i3g2000cwc.googlegroups.com>
Wrong.
I was not planning taking a long weekend before I posted, but that's
what ended up happening. I didn't have to mention it, but I felt that
I should in consideration of the people trying to help me.
Thanks for your help.
Terry
> As in "I'll post this question now, then go on a vacation. Let them sort
> this out, discuss the pro's and con's and when I'm back, I can pick up a
> solution, without having participated in the discussion, shown what I
> tried and where it failed, rectified false assumptions"?
>
> 26 to 31 ist exactly 5 days.
>
> --
> Josef M=F6llers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett
------------------------------
Date: Tue, 01 Aug 2006 13:31:21 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Using an input/csv file to rename files
Message-Id: <g69y7u8mkgm.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 1 Aug 2006, josef.moellers@fujitsu-siemens.com wrote:
Terry wrote:
>
>> My appologies for the 5 days inbetween posts, but I went on vacation
>> and unplugged for a few days.
>
> As in "I'll post this question now, then go on a vacation. Let them
> sort this out, discuss the pro's and con's and when I'm back, I can
> pick up a solution, without having participated in the discussion,
> shown what I tried and where it failed, rectified false assumptions"?
>
> 26 to 31 ist exactly 5 days.
That was uncalled for, especially since Terry apologized.
Ted
------------------------------
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 9544
***************************************