[28181] in Perl-Users-Digest
Perl-Users Digest, Issue: 9545 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 1 18:06:02 2006
Date: Tue, 1 Aug 2006 15: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 Tue, 1 Aug 2006 Volume: 10 Number: 9545
Today's topics:
Beginner: regex-error? <mstep@t-online.de>
Re: Beginner: regex-error? <mritty@gmail.com>
Re: Beginner: regex-error? <abigail@abigail.be>
Re: Beginner: regex-error? <mstep@t-online.de>
Re: Beginner: regex-error? <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Beginner: regex-error? <1usa@llenroc.ude.invalid>
Re: Beginner: regex-error? <someone@example.com>
Re: Beginner: regex-error? <1usa@llenroc.ude.invalid>
Re: foreach aliasing, my variables, and visibility in s <bik.mido@tiscalinet.it>
Re: foreach aliasing, my variables, and visibility in s <bik.mido@tiscalinet.it>
Re: foreach aliasing, my variables, and visibility in s <benmorrow@tiscali.co.uk>
Heisenbug! was: odd crash in file upload via CGI <msoulier@gmail.com>
Re: Heisenbug! was: odd crash in file upload via CGI <mritty@gmail.com>
Re: perl editor <abigail@abigail.be>
Re: Printing Hash Marks During File Download <hlarons@yahoo.com>
Re: Recursion <bik.mido@tiscalinet.it>
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Recursion <uri@stemsystems.com>
Re: Recursion <bik.mido@tiscalinet.it>
Re: Recursion <sherm@Sherm-Pendleys-Computer.local>
Re: Recursion <koko_loko_0@yahoo.co.uk>
Re: Unicode and Perl <bill@ts1000.us>
Re: Unicode and Perl <mgarrish@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 Aug 2006 22:42:21 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Beginner: regex-error?
Message-Id: <C0F5894D.295AB%mstep@t-online.de>
Hello happy Perlers,
it is very strange: I capture a string as I used it many times, and a
Boolean value is given back. All the day I meditated over this script, but
something very obvious I am missing.
Have a nice evening and sorry for this question
marek
############
#!/usr/bin/perl
use warnings;
use strict;
my (@lines);
while (<DATA>)
{
chomp;
push @lines, $_;
}
foreach my $line (@lines)
{
my $date = $line =~ /^([\d.]+)/;
# why is this regex wrong?
# I want to capture the dates: 17.07.2006 ...
print "\n$date";
}
__DATA__
17.07.2006 CC mU 58.00
17.07.2006 Fr. Knorr CC mU 60.00
18.07.2006 Unterföhring MUC Link CC mU 45.00
19.07.2006 CC mU 58.00
20.07.2006 MUC Hanauer Hermann/Wacki CC mU 55.00
21.07.2006 Claudio/Rock CC oU 55.00
24.07.2006 CC mU 54.00
24.07.2006 CC mU 50.00
24.07.2006 CC mU 55.00
25.07.2006 CC mU 82.00
26.07.2006 -3.7 Uhr! Königin MUC Wacki Bar oU 55.00
27.07.2006 hin rück Link CC mU 122.00
------------------------------
Date: 1 Aug 2006 13:44:25 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Beginner: regex-error?
Message-Id: <1154465065.414318.93330@h48g2000cwc.googlegroups.com>
Marek Stepanek wrote:
> my $date = $line =~ /^([\d.]+)/;
> # why is this regex wrong?
> # I want to capture the dates: 17.07.2006 ...
A pattern match in scalar context returns either true or false (really,
1 or ""). If you want it to return a list of the sub-captures, you need
to provide list context.
my ($date) = $line =~ /^([\d.]+)/;
The parentheses are not optional.
Paul Lalli
------------------------------
Date: 01 Aug 2006 20:47:58 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Beginner: regex-error?
Message-Id: <slrnecvffu.sce.abigail@alexandra.abigail.be>
Marek Stepanek (mstep@t-online.de) wrote on MMMMDCCXVIII September
MCMXCIII in <URL:news:C0F5894D.295AB%mstep@t-online.de>:
{}
{} my $date = $line =~ /^([\d.]+)/;
{} # why is this regex wrong?
{} # I want to capture the dates: 17.07.2006 ...
The regex isn't wrong. However, you are using the match in scalar context,
and then the match returns true/false.
Either print $1, or put the match in list context:
my ($date) = $line =~ /^([\d.]+)/;
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT
------------------------------
Date: Tue, 01 Aug 2006 23:01:23 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Beginner: regex-error?
Message-Id: <C0F58DC3.2963A%mstep@t-online.de>
On 01.08.2006 22:44, in article
1154465065.414318.93330@h48g2000cwc.googlegroups.com, "Paul Lalli"
<mritty@gmail.com> wrote:
> Marek Stepanek wrote:
>> my $date = $line =~ /^([\d.]+)/;
>> # why is this regex wrong?
>> # I want to capture the dates: 17.07.2006 ...
>
>
> A pattern match in scalar context returns either true or false (really,
> 1 or ""). If you want it to return a list of the sub-captures, you need
> to provide list context.
>
> my ($date) = $line =~ /^([\d.]+)/;
>
> The parentheses are not optional.
>
> Paul Lalli
>
Thank you Paul,
this was a quick answer to a silly question. But I would never imagined this
answer. Have to learn a lot again.
good night
marek
------------------------------
Date: Tue, 1 Aug 2006 13:46:11 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Beginner: regex-error?
Message-Id: <k5r4q3xcpq.ln2@goaway.wombat.san-francisco.ca.us>
On 2006-08-01, Marek Stepanek <mstep@t-online.de> wrote:
>
> it is very strange: I capture a string as I used it many times, and a
> Boolean value is given back.
That's because you've asked for a boolean.
> my $date = $line =~ /^([\d.]+)/;
> # why is this regex wrong?
> # I want to capture the dates: 17.07.2006 ...
Read perldoc perlop (not perldoc perlre), search for the string PATTERN,
and read down about m/PATTERN/cgimosx about what the match actually
returns in scalar versus list context. (Hint: you need list context
here.)
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information
------------------------------
Date: Tue, 01 Aug 2006 20:53:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Beginner: regex-error?
Message-Id: <Xns9812AC00B73FAasu1cornelledu@127.0.0.1>
Marek Stepanek <mstep@t-online.de> wrote in
news:C0F5894D.295AB%mstep@t-online.de:
> it is very strange: I capture a string as I used it many times, and a
> Boolean value is given back.
Not very strange. A match in scalar context returns a boolean value
indicating if the match succeded or not.
> #!/usr/bin/perl
>
>
> use warnings;
> use strict;
>
> my (@lines);
>
>
> while (<DATA>)
> {
> chomp;
> push @lines, $_;
> }
There is absolutely no good reason to read in all of the data only to
process it one line at a time.
>
> foreach my $line (@lines)
> {
> my $date = $line =~ /^([\d.]+)/;
> # why is this regex wrong?
> # I want to capture the dates: 17.07.2006 ...
The regex is not wrong per se ... As an aside it is not specific enough.
See below.
#!/usr/bin/perl
use warnings;
use strict;
LINE: while ( my $line = <DATA>) {
chomp $line;
last LINE unless length $line;
my ($date) = ( $line =~ /^(\d{2}\.\d{2}\.\d{4})/ );
print "$date\n" if defined $date;
}
__DATA__
17.07.2006 CC mU 58.00
17.07.2006 Fr. Knorr CC mU 60.00
18.07.2006 Unterföhring MUC Link CC mU 45.00
19.07.2006 CC mU 58.00
20.07.2006 MUC Hanauer Hermann/Wacki CC mU 55.00
21.07.2006 Claudio/Rock CC oU 55.00
24.07.2006 CC mU 54.00
24.07.2006 CC mU 50.00
24.07.2006 CC mU 55.00
25.07.2006 CC mU 82.00
26.07.2006 -3.7 Uhr! Königin MUC Wacki Bar oU 55.00
27.07.2006 hin rück Link CC mU 122.00
D:\UseNet\clpmisc> cap
17.07.2006
17.07.2006
18.07.2006
19.07.2006
20.07.2006
21.07.2006
24.07.2006
24.07.2006
24.07.2006
25.07.2006
26.07.2006
27.07.2006
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 01 Aug 2006 21:25:06 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Beginner: regex-error?
Message-Id: <SEPzg.151606$I61.100755@clgrps13>
A. Sinan Unur wrote:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> LINE: while ( my $line = <DATA>) {
> chomp $line;
> last LINE unless length $line;
^^^^^^^^^
Don't you mean:
next LINE
> my ($date) = ( $line =~ /^(\d{2}\.\d{2}\.\d{4})/ );
> print "$date\n" if defined $date;
> }
Or more simply:
LINE: while ( my $line = <DATA> ) {
next LINE unless $line =~ /^(\d{2}\.\d{2}\.\d{4})/;
print "$1\n" if $1;
}
And using defaults:
while ( <DATA> ) {
next unless /^(\d{2}\.\d{2}\.\d{4})/;
print "$1\n" if $1;
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 01 Aug 2006 21:41:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Beginner: regex-error?
Message-Id: <Xns9812B40136978asu1cornelledu@127.0.0.1>
"John W. Krahn" <someone@example.com> wrote in news:SEPzg.151606
$I61.100755@clgrps13:
> A. Sinan Unur wrote:
>>
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> LINE: while ( my $line = <DATA>) {
>> chomp $line;
>> last LINE unless length $line;
> ^^^^^^^^^
> Don't you mean:
>
> next LINE
Well, at the time I did not, because I considered a blank line to be the
end of input. On the other hand, your suggestions makes sense.
> while ( <DATA> ) {
> next unless /^(\d{2}\.\d{2}\.\d{4})/;
> print "$1\n" if $1;
> }
You don't really need the if $1 test, either.
And, yes, this is much cleaner than what I had written. Thanks.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 1 Aug 2006 21:49:44 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <usavc2l97kmvgltt0lptt0ckl9f9f3q658@4ax.com>
On Tue, 1 Aug 2006 15:57:42 +0100, Ben Morrow
<benmorrow@tiscali.co.uk> wrote:
>> 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:
Although that's indeed what both 'perldoc -q closure' and 'perldoc
perlref' claim, I regard it as a standard misconception that closures
*are* anonymous subs. In fact anonymity is orthogonal to the fact that
subs "magically refer to the lexical variables that were around when
they were defined", which is the distinctive charachteristic of a
closure.
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: 1 Aug 2006 21:59:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <fdcvc2l1dl9efdhtvf674vbnhc7qsqq08c@4ax.com>
On 1 Aug 2006 21:49:44 +0200, Michele Dondi <bik.mido@tiscalinet.it>
wrote:
>Although that's indeed what both 'perldoc -q closure' and 'perldoc
>perlref' claim, I regard it as a standard misconception that closures
>*are* anonymous subs. In fact anonymity is orthogonal to the fact that
>subs "magically refer to the lexical variables that were around when
>they were defined", which is the distinctive charachteristic of a
>closure.
Oh, and sorry for the addition, but
<http://en.wikipedia.org/wiki/Closure_%28computer_science%29> does
confirm my POV.
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 21:27:47 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <33q4q3-512.ln1@osiris.mauzo.dyndns.org>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Tue, 1 Aug 2006 15:57:42 +0100, Ben Morrow
> <benmorrow@tiscali.co.uk> wrote:
>
> >> 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:
>
> Although that's indeed what both 'perldoc -q closure' and 'perldoc
> perlref' claim, I regard it as a standard misconception that closures
> *are* anonymous subs.
And I that a closure is simply a sub with its own scope :). They are
*not* the same thing: the important property of a closure is that you
can have *many copies* of the same sub *each with its own scope*.
Compare
sub mkfoo {
my $f = shift;
sub bar {
return $f;
}
return \&bar;
}
with
sub mkfoo {
my $f = shift;
return sub {
return $f;
};
}
. The first will always create subs that return the same value, whereas
the second will create subs that return different values. Perl will give
you a 'Variable will not stay shared' warning for this reason.
> In fact anonymity is orthogonal to the fact that
Yes, of course. In languages that implement named subs as closures the
(equivalent of) the first example would work as well.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. benmorrow@tiscali.co.uk
------------------------------
Date: 1 Aug 2006 11:54:49 -0700
From: "msoulier" <msoulier@gmail.com>
Subject: Heisenbug! was: odd crash in file upload via CGI
Message-Id: <1154458489.031455.281050@75g2000cwc.googlegroups.com>
msoulier wrote:
> Can't coerce GLOB to string in entersub at
> /usr/lib/perl5/site_perl/5.8.0/Persistence/Object/Simple.pm line 125.
And believe it or not, this little bit of code prevents it from
happening.
foreach my $param ($cgi->param)
{
my $val = $cgi->param($param);
my $string = "$val";
}
Seems completely unrelated, but if I don't stringify the incoming
parameters once, then it crashes.
Any perl gurus with black magick to explain this one for me?
Cheers,
Mike
------------------------------
Date: 1 Aug 2006 12:04:23 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Heisenbug! was: odd crash in file upload via CGI
Message-Id: <1154459063.860910.17420@75g2000cwc.googlegroups.com>
msoulier wrote:
> msoulier wrote:
> > Can't coerce GLOB to string in entersub at
> > /usr/lib/perl5/site_perl/5.8.0/Persistence/Object/Simple.pm line 125.
^^^^^
> Any perl gurus with black magick to explain this one for me?
5.8.0 is notoriously buggy. You use known-buggy software, you
encounter bugs. Upgrade.
Paul Lalli
------------------------------
Date: 01 Aug 2006 20:17:20 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: perl editor
Message-Id: <slrnecvdmg.sce.abigail@alexandra.abigail.be>
Josef Moellers (josef.moellers@fujitsu-siemens.com) wrote on MMMMDCCXVIII
September MCMXCIII in <URL:news:eamtml$7ob$2@nntp.fujitsu-siemens.com>:
{} Abigail wrote:
{} > Josef Moellers (josef.moellers@fujitsu-siemens.com) wrote on MMMMDCCXVII
{} > September MCMXCIII in <URL:news:eal0kq$f1r$1@nntp.fujitsu-siemens.com>:
{} > @@ syracuse wrote:
{} > @@ > Hi
{} > @@ > anyone knows what is a good free editor to use for perl ?
{} > @@ > Thanks
{} > @@ > Syracuse
{} > @@
{} > @@ vi?
{} >
{} >
{} > vi isn't free. Although many good vi clones are.
{}
{} Hmm, didn't know that. I usually call "vim" as "vi".
{}
vim isn't vi. Despite toy OS distro's firing up 'vim' is you type 'vi'.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: Tue, 01 Aug 2006 18:39:41 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Re: Printing Hash Marks During File Download
Message-Id: <slrnecv7vd.sn.hlarons@Beagle.mylocal.net>
On Mon, 31 Jul 2006 18:01:29 -0000, HaroldWho wrote in comp.lang.perl.misc:
> I am using the Net::POP3 module to retrieve mail from a dialup POP3 server.
> program gives no indication that the d/l is going OK.
>
> I'd like to print hash marks during the d/l, much like an ftp d/l does, but
Thanks to all of you for sharing your ideas. I'll be following up on all of
them (or until I can make one work :-).
HW
--
Powered by Slackware 10.2 Linux -- Kernel 2.6.13
News Reader slrn 0.9.8.1
------------------------------
Date: 1 Aug 2006 20:06:10 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Recursion
Message-Id: <jt5vc2dv25ig2tpkjiuq6b0rmlhpoji7fc@4ax.com>
On Tue, 1 Aug 2006 18:45:30 +0100, "kokolo" <koko_loko_0@yahoo.co.uk>
wrote:
>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...
[snip]
And you still haven't learnt not to top-post and to quote properly
instead...
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 19:14:00 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eao5la$bbk$1@news.al.sw.ericsson.se>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:jt5vc2dv25ig2tpkjiuq6b0rmlhpoji7fc@4ax.com...
> On Tue, 1 Aug 2006 18:45:30 +0100, "kokolo" <koko_loko_0@yahoo.co.uk>
> wrote:
>
> >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...
> [snip]
>
> And you still haven't learnt not to top-post and to quote properly
> instead...
>
>
> Michele
> --
I admit, I suck . Hope it's temporary
kokolo
------------------------------
Date: Tue, 1 Aug 2006 19:10:47 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eao5f9$bar$1@news.al.sw.ericsson.se>
Thx a lot.
At this very moment i know nothing about referencing in Perl so I'll have
to learn it.
I just don't know if I want to pass the entire set to subroutine as my
concept was to keep "pivot" while "sorting" left and right side
recursively.
kokolo
<xhoster@gmail.com> wrote in message
news: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, 01 Aug 2006 15:11:20 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Recursion
Message-Id: <x73bcgfezr.fsf@mail.sysarch.com>
>>>>> "k" == kokolo <koko_loko_0@yahoo.co.uk> writes:
k> 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.
k> I didn't have a slightest intention (that would be really ignorant!) on
k> writing anything that would be faster than any C implemented
k> quiscksort, or Perl's bulitin mergesort, or Radix sort, or any of other
k> C-like languages implemented O(NlogN) sorts,
radix is O(N) in its optimal case.
and if you know the others are average or worst case O(N log N) why are
you experimenting with them? you should read a good book on sort
algorithms anyhow. even thinking that memoize could help in a sort is a
sign you need to understand them better.
k> I just wanted to write a quicksort in Perl and compare it to e.g.
k> Shellsort. I was curious how to write these sorting algorithms in
k> Perl as I'm learning Perl and thought algorithms would be
k> interesting exercises. I'm only wondering why it's not as fast as
k> I expected it to be.
then why didn't you say this was a learning/teaching experiment? you
would have saved a lot of annoyance from many posters and readers.
you didn't show any code nor explain that you wondered why your code is
not what you expected. do you know that for small input lists, the
overhead of a sort will usually outweigh the growth curve? you need to
use some serious sized input to show the growth curves and to then
compare different algorithms. and your coding skills may not be up to
doing recursive sorts (as that is obvious by your questions) so why not
learn perl with some easier things? sort algorthms are not going to use
many constucts that you need to learn such as regexes and hashes (though
the orcish manoever does use hashes). again, i suggest you read my sort
paper and sort::maker's docs just to learn some more about sorting. and
try a different way to learn perl, sorting is too limited in its
educational scope.
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 21:29:34 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Recursion
Message-Id: <3navc2hlr64e2dau12pgl1ou1e2eugumvi@4ax.com>
On Tue, 1 Aug 2006 17:18:23 +0100, "kokolo" <koko_loko_0@yahoo.co.uk>
wrote:
>-----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.
Although we *do* recommend to use warnings all the time, there are
situations in which you know what your doing and you are aware that a
certain statement will issue one particular spurious warning: in that
case you can *locally* disable that particular (family of) warning(s)
in a lexical scope as close as possible to the statement itself.
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, 01 Aug 2006 15:52:26 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Recursion
Message-Id: <m2u04w44jp.fsf@Sherm-Pendleys-Computer.local>
Uri Guttman <uri@stemsystems.com> writes:
> 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.
Another great resource if you're studying that sort of thing is O'Reilly's
"Mastering Algorithms With Perl".
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 1 Aug 2006 21:29:05 +0100
From: "kokolo" <koko_loko_0@yahoo.co.uk>
Subject: Re: Recursion
Message-Id: <eaodim$fkn$1@news.al.sw.ericsson.se>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x73bcgfezr.fsf@mail.sysarch.com...
> >>>>> "k" == kokolo <koko_loko_0@yahoo.co.uk> writes:
>
> k> 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.
>
> k> I didn't have a slightest intention (that would be really ignorant!)
on
> k> writing anything that would be faster than any C implemented
> k> quiscksort, or Perl's bulitin mergesort, or Radix sort, or any of
other
> k> C-like languages implemented O(NlogN) sorts,
>
> radix is O(N) in its optimal case.
>
> and if you know the others are average or worst case O(N log N) why are
> you experimenting with them? you should read a good book on sort
> algorithms anyhow. even thinking that memoize could help in a sort is a
> sign you need to understand them better.
>
> k> I just wanted to write a quicksort in Perl and compare it to e.g.
> k> Shellsort. I was curious how to write these sorting algorithms in
> k> Perl as I'm learning Perl and thought algorithms would be
> k> interesting exercises. I'm only wondering why it's not as fast as
> k> I expected it to be.
>
> then why didn't you say this was a learning/teaching experiment? you
> would have saved a lot of annoyance from many posters and readers.
>
> you didn't show any code nor explain that you wondered why your code is
> not what you expected. do you know that for small input lists, the
> overhead of a sort will usually outweigh the growth curve? you need to
> use some serious sized input to show the growth curves and to then
> compare different algorithms. and your coding skills may not be up to
> doing recursive sorts (as that is obvious by your questions) so why not
> learn perl with some easier things? sort algorthms are not going to use
> many constucts that you need to learn such as regexes and hashes (though
> the orcish manoever does use hashes). again, i suggest you read my sort
> paper and sort::maker's docs just to learn some more about sorting. and
> try a different way to learn perl, sorting is too limited in its
> educational scope.
>
> uri
I did show the code, please take a look at the first post in the thread.
I'm not thinking I'll learn a lot of Perl by writing sorting algorithms, but
I found it an interesting challenge. After reading what the algorithm does I
tried to implement it in my weak Perl. And I did it but it's not as many
times faster than e.g. ShellSort than I expected it to be. So I asked for an
advice as the code does the job.
thx,
kokolo
------------------------------
Date: 1 Aug 2006 13:16:19 -0700
From: "Bill H" <bill@ts1000.us>
Subject: Re: Unicode and Perl
Message-Id: <1154463379.051025.74840@i3g2000cwc.googlegroups.com>
Mumia W. wrote:
> 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=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
> >
>
> 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.
Thanks to everyone for all the suggestions. The unicode is made by
saving the text file with windows XP's notepad. I will try these
suggestions
Bill H
------------------------------
Date: 1 Aug 2006 14:07:40 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Unicode and Perl
Message-Id: <1154466460.697779.33630@i3g2000cwc.googlegroups.com>
Bill H wrote:
> Mumia W. wrote:
> > On 08/01/2006 08:34 AM, Bill H wrote:
> >
> > 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.
>
> Thanks to everyone for all the suggestions. The unicode is made by
> saving the text file with windows XP's notepad. I will try these
> suggestions
>
What does that tell anyone, though? Notepad will let you save in UTF-8
and little- and big-endian UTF16 (which it likes to call "unicode").
Which encoding did you choose?
Matt
------------------------------
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 9545
***************************************