[10214] in Perl-Users-Digest
Perl-Users Digest, Issue: 3807 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 23 22:07:20 1998
Date: Wed, 23 Sep 98 19:00:17 -0700
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, 23 Sep 1998 Volume: 8 Number: 3807
Today's topics:
Re: Array of hashes: a better way? (Andre L.)
Re: Concatenating 3 strings <r28629@email.sps.mot.com>
Re: Concatenating 3 strings (Abigail)
Re: exec cgi in apache 1.3.1 <sevo@inm.de>
Re: exec cgi in apache 1.3.1 <jarrowwx@stt3.com>
File Reading <slug@labyrinth.net.au>
Re: How to implement (efficiently) an X minute cycle ? (David Formosa)
Re: mod_perl woes <jdw@dev.tivoli.com>
Re: Perl & Java - differences and uses (David Formosa)
Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
perl and fly... <dmckeown@istar.ca>
Re: Perl and Oraperl <eashton@bbnplanet.com>
Re: Poll: How Did You Learn Perl? <merlyn@stonehenge.com>
Re: Poll: How Did You Learn Perl? <rick.delaney@shaw.wave.ca>
Re: problems with dates being off by 1 day <m_ching@hotmail.com>
Re: Q: Picking an element from a hash (not knowing whic (Mark-Jason Dominus)
Re: Rotating an array. (Larry Wall)
Re: Rotating an array. (MJ Lee)
Re: Rotating an array. (Larry Rosler)
Re: sending email attachments using just perl? <m_ching@hotmail.com>
Sorting Array Of Directories via ABC, not date... (Vikram Pant)
Re: Sorting Array Of Directories via ABC, not date... (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Sep 1998 19:08:24 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Array of hashes: a better way?
Message-Id: <alecler-2309981908240001@dialup-534.hip.cam.org>
In article <saryaraecjg.fsf@camel.fastserv.com>, Uri Guttman
<uri@camel.fastserv.com> wrote:
> [snip]
> i can't tell the difference between S and s!
That's what happens to people who never use capitals. <smurk>
Andre
------------------------------
Date: Wed, 23 Sep 1998 18:05:49 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Concatenating 3 strings
Message-Id: <36097ECD.5D77CB5B@email.sps.mot.com>
Dave Barnett wrote:
>
> leah_price@ibi.com wrote:
> > $subject = $a.$b; works.
> >
> Well, demangling the pseudo code you have above, I get it to work fine.
> 1. $subject = $a . $b . 'works.';
> -- What is the ; doing where you have it????
>
I think he meant to say:
$subject = $a.$b; # works.
In any case,
$subject = $a.$b."String"; # Works for me.
So?????
#:)
------------------------------
Date: 24 Sep 1998 00:50:26 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Concatenating 3 strings
Message-Id: <6uc50i$l4o$2@client3.news.psi.net>
leah_price@ibi.com (leah_price@ibi.com) wrote on MDCCCXLIX September
MCMXCIII in <URL:news:6ubnf4$82f$1@nnrp1.dejanews.com>:
++
++
++ I would like to concatenate three strings. The first two are variables, the
++ third is a text string.
++
++ $subject = $a.$b; works.
++
++ But when I try to add the text string it doesn't work. Am I doing something
++ wrong?
++
++ $subject = $a.$b."String";
What do you mean "it doesn't work"? Is it sitting on the floor all day,
making funny faces at you? Is it on strike? Is it on holiday?
What is happening, and what are you expecting?
$a.$b."String";
is fine, and so is:
"$a${b}String";
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: Thu, 24 Sep 1998 01:45:43 +0200
From: Sevo Stille <sevo@inm.de>
Subject: Re: exec cgi in apache 1.3.1
Message-Id: <36098827.B7D3E02D@inm.de>
John Arrowwood wrote:
> If you
> choose the latter approach, you might want to only
> over-ride it for that directory, not all, by using
> a .htaccess file.
Time for my standard disclaimer: .htaccess files provide directory
administrators without server administration privileges with a
controlled subset of configuration directives pertaining to their
directory. Except for that particular case, they are not the right place
for per-directory settings! Anything possible in a .htaccess file (and
more) can be done inside Directory or Location sections of the config
file.
Apart from questionable security of putting configuration files in a
world readable (and often script-writeable) place, .htaccess files have
to be searched, read and parsed at every hit, and on heavily loaded
servers, that extra stat and filesystem activity can be particularily
undesirable.
Sevo
--
Sevo Stille
sevo@inm.de
------------------------------
Date: Wed, 23 Sep 1998 17:09:52 -0700
From: John Arrowwood <jarrowwx@stt3.com>
To: sevo@inm.de
Subject: Re: exec cgi in apache 1.3.1
Message-Id: <36098DD0.82D7859A@stt3.com>
Sevo Stille wrote:
>
> John Arrowwood wrote:
> > a .htaccess file.
>
> Time for my standard disclaimer: .htaccess files provide directory
> administrators without server administration privileges with a
> controlled subset of configuration directives pertaining to their
> directory. Except for that particular case, they are not the right place
> for per-directory settings! Anything possible in a .htaccess file (and
> more) can be done inside Directory or Location sections of the config
> file.
>
> Apart from questionable security of putting configuration files in a
> world readable (and often script-writeable) place, .htaccess files have
> to be searched, read and parsed at every hit, and on heavily loaded
> servers, that extra stat and filesystem activity can be particularily
> undesirable.
Thank you, and I agree with everything you said.
Of course, if you don't have access to the server configuration,
like if the page being edited is the home page on your ISP's web
server... And the context of the original message did not indicate
whether or not he had such access (though in this news-group, I
guess it would have been a safe bet, eh?)
Besides, the .htaccess was at best a second choice, not first...
------------------------------
Date: Thu, 24 Sep 1998 11:54:22 +1000
From: Reiner <slug@labyrinth.net.au>
Subject: File Reading
Message-Id: <3609A64E.E8E2875B@labyrinth.net.au>
In some code I need to read a file until a certain line is reached so
that I can read in the following lines. This code works well:
$question = 1;
# Go to current question
while (<FILE> != $question) { }
The problem is if the $question does not exist. I tried things like the
line below but had no luck.
while ((<FILE> != $question)) && (!$!) { }
------------------------------
Date: 24 Sep 1998 10:16:55 +1000
From: dformosa@zeta.org.au (David Formosa)
Subject: Re: How to implement (efficiently) an X minute cycle ?
Message-Id: <6uc31n$9t4$1@godzilla.zeta.org.au>
In <6ubd4l$68f$1@client3.news.psi.net> abigail@fnx.com (Abigail) writes:
[...]
>This doesn't use a fork():
>while (1) {
> $then = 600 + time;
> do some stuff;
> sleep ($then - time);
>}
What happens when time>$then ? Experements seem to indercate that it
ether hangs or sleeps for a very long time.
------------------------------
Date: 23 Sep 1998 17:27:24 -0500
From: Jim Woodgate <jdw@dev.tivoli.com>
Subject: Re: mod_perl woes
Message-Id: <obr9x2h3cj.fsf@alder.dev.tivoli.com>
ryan@mail.ramresearch.com (Ryan McGuigan) writes:
> For example, I've been working on a message board program, it displays
> different things depending on the post or Query string input. Without any
> input it just displays the threads posted to the board. When run through
> mod_perl, it will SOMETIMES run as though it's received some kind of
> input, even though it hasn't. Any thoughts? I've never used mod_perl
> before, so any advice is appreciated.
read through mod_perl_traps.pod...
--
Jim Woodgate
Tivoli Systems
E-Mail: jdw@dev.tivoli.com
------------------------------
Date: 24 Sep 1998 10:01:26 +1000
From: dformosa@zeta.org.au (David Formosa)
Subject: Re: Perl & Java - differences and uses
Message-Id: <6uc24m$8c6$1@godzilla.zeta.org.au>
In <6ubg92$1bg$1@nnrp1.dejanews.com> bjohnsto_usa_net@my-dejanews.com writes:
>In article <906445285.800391@thrush.omix.com>,
> Zenin <zenin@bawdycaste.org> wrote:
[...] My understanding is that Java byte code can't do lambda
>> style functions for instance, thus making things like a Java
>> byte code backend for Perl [...]
>What do you mean by lambda style function?
A lambda style function is a function that has no name. For example in
perl I can go,
$var = sub {
$x =shift;
$y =shift;
return $x+$y;
}
and in lisp I can go
(setf var (lambda (x y) (+ x y)))
The function is now only advalable via the verable that it has been assigned
to it.
>Do you have any links to information about them or books in which they are
>described.
Any site or book that discusses functional programing should also cover
lambda functions and closures.
------------------------------
Date: 24 Sep 1998 01:47:49 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <906601672.578393@thrush.omix.com>
George Reese <borg@imaginary.com> wrote:
>snip<
: I disagree completely. As I discussed later in the post, OO is better
: suited to repeatedly building quality software because it comes from
: components which have already been proven.
Whoa, ok stop right there.
Please define what a "proven component" for us. Is it not simply
a given module of software (or "object", or "module", or "library",
etc) that has proven its reliability and functionality through both
use and testing? If you do not agree with this definition, please
state *exactly* where and why it fails to define "proven component".
Now, given this definition of a component, would it not apply to
nearly everything in /usr/lib?
If the term "proven component" can not be applied to C libraries such
as libcurses, libstdio, libm please give us exact and logical reasons
why they do not.
: And yes, that does substantially change the nature of my original argument.
Yes, it does. It makes your comments even more suspect as they imply
that other paradigms have failed to build on proven components, which
is so completely and totally false it's simply humorous. This is
because to follow through this line of "logic", one must conclude
that no other paradigm has been able to build on the proven
components of the past, which is *dead wrong*, as `ls /usr/lib`
proves.
And yes, your comments do at best simply imply this line of thought,
and at worst they preach it.
But read on before you reply, as I'm about to use your own
statements about OO as proof that Perl is better then Python for
OO use.
>snip<
: No, but I am implying that something about OO design patterns make them
: better suited to encapsulationin reusable components.
Ok, I'll accept this. Now, your next task is to offer proof that
this logic is correct, as you have not given us any as yet. Also,
you need to define what this "something" is.
Now, if the primary feature of OO design patterns is to encapsulate
reusable components (which I do not argue), then one with a
*current* background in Perl and Python *MUST* conclude that Perl, not
Python, is the better tool to implement such designs.
*HOW*, *WHY* you ask? Simple. With the release of Perl
version 5.005 comes data encapsulation support to rival Java.
No, I'm not joking. Yes, perl now has full core support for the
"private", "protected", "public" paradigms of Java.
You can argue the beauty of Perl code, however with this new release
one can no longer argue its abilities to encapsulate data.
See "perldoc fields" for further information and actual *proof*.
: In fact, I
: intentionally qualified 'design patterns' with 'OO' so as to avoid
: being interpreted as saying anything at all about non-OO design
: patterns.
Fine. This however, still does not change the fact that Perl's
abilities to encapsulate data surpass Pythons and rival Java's.
Before you discount this statement, make *very* sure you have
read the change log deltas for *5.005*. To rebut my above arguments
without such research is to simply talk out of your ass.
>snip<
: : this sounds more like an argument for reusability of designed
: : components rather than an argument for the repeatability of the
: : design and production method.(again, see above)
:
: It is a combination of the two. Given:
: * OO is a paradigm based on the use and reuse of designed components.
Agreed. This does not however, discount the fact that other
paradigms also support reusable components (see above about
/usr/lib). Indeed, the heart and sole of Unix was built entirely
on reusable ideals. "Build a tool that does one thing and does
it well, then connect those tools together into larger tools".
/usr/bin/* has got to be the ultimate example of code reuse in
action, and the funny thing is none of it is OO. It is, most
of all, proof that code reuse has been around long before OO
was just a gleam in its father's eye.
: * Given proven behaviour of the parts,
Aka, /usr/lib
: a process for putting together the parts
Aka, "foo | bar | baz"
: that is repeatable
Aka, "foobar () { foo | bar | baz; }"
: is going to have an advantage in predictably producing a quality whole.
Correct.
: - Thus OO has an advantage over other paradigms.
Incorrect. Nearly everything you've stated applies no less to
other paradigms. What is *different* about OO that gives it this
advantage?
I'll agree that the encapsulation abilities of objects make
namespace collisions rarer (but not impossible or even uncommon).
The problem with your arguments however, is two fold. Encapsulation
is not your main focus, and Perl's *current* encapsulation abilities
out shine Python. If one counts lambda functions as a form of
encapsulation (I very much do), then Perl also out shines Java in
this aspect as well. -And no, Java does not have anything to match
lambda functions. Function pointers yes, but not lambda functions,
which are quite a different animal.
>snip<
: : Thus far, I am unconvinced by your arguments that OO offers any more
: : assurances of *quality* code production than following a good, sound
: : structural approach with a procedural language --- I am not saying OO
: : has not given us anything, or that it is worthless, or that some
: : problems might not be more ammenable to OO design --- just that it
: : does not appear to be by fiat "the best method for most software
: : production".
: So the problem is whether or not I have shown OO can reliably produce
: quality code?
No. Read the paragraph again, with particular note of the phrase,
"offers any more assurances". No one is arguing that OO can or
can not reliably produce quality code, we are arguing that it
has any *greater* abilities to do so then other paradigms.
: From the preceding paragraph, it sounds more like you
: should be saying that I have not shown how OO can reliably produce
: quality code for 'new situations' defined as you defined them above.
: I can agree that I have not shown that, but I disagree that I have not
: shown the former.
We don't care if OO can produce quality code. We care about
*proof* that it can create quality code with *any more
reliabilities* then other paradigms. We care about *proof* that
other paradigms have even fallen short of this [producing
quality code] at *all*, and if so *how* OO does this any better.
We care about actual *evidence*, not simple declarations.
We do not care about your statements that OO does do this better,
we only care about the *how* and *why* of your arguments.
Offer *proof*, not declarations. Anyone can declare anything, but
that doesn't make it so.
: As far as new situations go, that argument is much more complex. I
: would say that the principle of encapsulation at the heart of the OO
: paradigm is better suited to the creation of truly reusable design
: patterns.
Ok, *now* you're starting to make some more logical statements.
: I think though that I want to leave that argument for
: another day,
As soon as you have found the arguably single reason (proof?) that
OO may have an edge over other paradigms, you bail out...?
>snip<
: I guess I do not understand the type of freedom you are speaking of
: here. Given a problem, there is more than one way to break it up in
: terms of the classes and their public interfaces, however, IMHO, that is not
: the realm of the programmer in an OO software engineering process.*
:
: * Practically, speaking, programmers today need to have this knowledge
: due to the tremendous labour shortage and the lack of sophistication
: still found in most OO development.
Exactly. Finally we are getting somewhere.
At issue here is the academic "correctness" of splitting up the
process into small enough parts so that the "programmer" is so
low on the totum poll they need not apply much (none if possible)
creative thought to implement a given design in code as this will
have all been done long before this part of the process (by the
designers and/or programming lead). Furthermore, they will be
following a known pattern to complete this task, thus reducing
the need or even the likelihood for creative thought (at this
level) even further.
As you have also just stated, this is not currently practical.
We however, will also argue that even it is was practical, it
is not desirable. This argument will be be based on the fact
that we are in software development solely because we are not
monkeys and not only do we think for ourself, we empirically
detest any environment in which we can not think for ourself
AND act on those thoughts.
I relate this back to theatre myself, where I originally came
from (technical stage lighting and special f/x). Of course
the director, lighting designer (me, typically), set designer,
etc had the last word on the overall designs and in the case
of the director the actions of the performers. However, the
performers, stage techs, etc also are free during the entire
process to offer and act on there own thoughts.
I'm reminded of the movie, "Tucker: The Man and the Machine".
In the movie, the foreman meets with Tucker to tell him he
had changed a primary design aspect of the car without his
consent (for safety issues). Tucker, with an *extremely* pissed
off look on his face replies to this with, "If you *ever*, *EVER*
do something like that again!!!"... pause ... Tucker smiles ... "I'll
be forced to give you a raise!".
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Thu, 24 Sep 1998 00:37:50 GMT
From: Dave Mckeown <dmckeown@istar.ca>
Subject: perl and fly...
Message-Id: <3609958F.93EF9EF0@istar.ca>
Anyone know of any good perl scripts that use fly and take input then
convert it a graphic?
I need to do this I think the way I would do it would be
take the input, read the characters, assign them to values of fly code,
then print the vlaues added up
$flyprog = "d:\\server\cgi-win\fly.exe";
$outfile = "temp.gif";
open(FLY,"| $flyprog -o $outfile ");
print FLY "new\n";
print FLY "$d-value \n";
print FLY "$a-value \n";
print FLY "$v-value \n";
print FLY "$e-value \n";
close(FLY);
$d-value, etc would be the proper fly code to produce the letter..
Does it sound like I'm on the right track? any suggestions examples?
------------------------------
Date: Thu, 24 Sep 1998 00:37:31 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Perl and Oraperl
Message-Id: <360991E0.A9FB1742@bbnplanet.com>
rzmw30 wrote:
> Thank you Elaine Ashton! It works fine.
> Doug
Your welcome rzmw...er, Doug! It's nice to be thanked. :) Enjoy.
e.
"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon." R. Carver
------------------------------
Date: Wed, 23 Sep 1998 23:27:49 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Poll: How Did You Learn Perl?
Message-Id: <8c1zp2v28v.fsf@gadget.cscaper.com>
>>>>> "Colin" == Colin Kuskie <ckuskie@cadence.com> writes:
[and evilly cc:'ed me without marking it as such... for which I've
killfiled other people. PLEASE FIX YOUR NEWSREADER.]
Colin> I don't know why Randal
Colin> left. Nobody beat him up, maybe he's just overwhelmed by the volume.
>>
>> Define "left". That's not right. :)
Colin> To stop reading or drastically reduce the number of one's postings to a
Colin> newsgroup:
Colin> Larry Wall and Randal Schwartz left clp.misc.
I'd certainly put Larry's complete lack of postings for two years in a
wholly different category than my 1-4 postings a day. True, I no
longer post 15 items a day... I've subcontracted that to Tom Phoenix. :)
But "left" also implies "not reading". There has never been a time
when I've *not read* clp.misc during its existance. This is
completely distinct from Larry and Tom's hiatus periods, where they
were not even reading the group. I suspect Larry still isn't actually
reading clp.misc, but relies on carefully selected Dejanews
searches. :)
Colin> See, it's simple when you can invent your own defintions for words :)
Let's say the word "free" means "with peanut butter"
(ducking)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Thu, 24 Sep 1998 01:14:22 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Poll: How Did You Learn Perl?
Message-Id: <36099E60.A8D127A0@shaw.wave.ca>
John Porter wrote:
>
> From what resource(s) did you learn Perl?
>
> . Llama v.1
> . Llama v.2
> . Camel v.1
> . Camel v.2
I feel strange saying this, but I've only glanced at my friend's Camel
once or twice. (I recall it was helpful).
> . Other book (give name)
> X Docs included in the distribution
These are excellent. An absolute pleasure to read, especially compared
to other man pages. They're just so good I've never really felt a
strong need for a book. I'm sure I'll break down some time--the
O'Reilly books are a bit tempting.
> X Something on the WWW
> X Studying existing code
Primarily on c.l.p.misc. I should also mention that fountain of
information, a2p.
I would like to take credit for introducing Perl to a half-dozen or so
of my co-workers.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Wed, 23 Sep 1998 15:38:42 -1000
From: "Michael Ching" <m_ching@hotmail.com>
Subject: Re: problems with dates being off by 1 day
Message-Id: <360978fe.0@news.hawaii.rr.com>
passme
remember- 0 is the first number.....
>I have an online calendar program I got off the www. It gets heavy use at
>my site. The problem is this, 99% of the time everything appears find,
once
>and a while, dates are displayed 1 day off.
>
>We have the newest version of Perl (we just got the new version a few days
>ago).
>Anyone have any ideas
>
>--
>Troy Bull
>Sr. Programmer Analyst
>University of Northern Iowa
>http://bull.its-is.uni.edu
>
>
------------------------------
Date: 23 Sep 1998 21:06:33 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Q: Picking an element from a hash (not knowing which!) [Zorn's lemma?]
Message-Id: <6uc5up$rcl$1@monet.op.net>
In article <3609472D.3087@entheosengineering.com>,
Rich Grise <richgrise@entheosengineering.com> wrote:
>One time, I saw a solution for "The Towers of Hanoi" in
>one line of APL.
That doesn't seem like a big deal; Hanoi is so simple you can implement
it in one line in almost any reasonable language without even
obfuscating. For example, two lines of Perl:
sub h;sub h{my($n,@p)=@_;$n&&h$n-1,@p[0,2,1];print "$n: $p[0]=>$p[1]
";$n&&h$n-1, @p[2,1,0]}h shift()-1, A .. C
% perl /tmp/hanoi.pl 3
0: A=>B
1: A=>C
0: B=>C
2: A=>B
0: C=>A
1: C=>B
0: A=>B
You could probably shorten this up a good deal if you were good at
obfuscation, which I'm not. Certainly APL's mighty powers of source
code compression are unnecessary here.
I agree with you that APL is an awfully peculiar language, but I don't
think this is a good example if you want to demonstrate that. Maybe a
better example:
p<-2=+/0=(1+iota(n-1))jot.|iota n
which I believe will generate a list of all the prime numbers between 1
an n. (I did not test this, having no APL system handy.) Note for APL
illiterates: The <- here represents a little arrow that points to the
left; `iota' represents the Greek letter iota, and `jot' represents a
small circle, centered vertically.
Anyway, count yourself lucky. The only readable APL programs are one
line long. Any longer than that and they start to turn into swamps.
------------------------------
Date: 23 Sep 1998 16:42:53 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: Rotating an array.
Message-Id: <6uc11t$o44@kiev.wall.org>
In article <MPG.10731134b9d1cf8f9897b5@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>my @a = ('a' .. 'z');
>my $rot = 2;
>
>timethese (1 << (shift || 0), {
> Slice => sub { @a = @a[$rot .. $#a, 0 .. $rot - 1] },
> Splice => sub { push @a, splice @a, 0, $rot },
>} );
>
>Benchmark: timing 16384 iterations of Slice, Splice...
> Slice: 16 secs ( 7.29 usr 0.04 sys = 7.33 cpu)
> Splice: 0 secs ( 0.63 usr 0.01 sys = 0.64 cpu)
This does not surprise me. There's a particular optimization in Perl
which attempts to recognize when an array is being rotated by shifting
(or splicing, in this case) elements off the front and pushing them on
the end. When Perl sees this sort of activity, it extends the
allocation of the array out several times longer, so that lots of
elements can be added on the end without having to copy existing
elements down so frequently. (When elements are shifted off the front,
it merely bumps the pointer to the front of the array, so that part is
already quite efficient.)
A similar optimization is done on rotated strings.
Larry
------------------------------
Date: Thu, 24 Sep 1998 00:42:09 GMT
From: mjlee@amherst.edu (MJ Lee)
Subject: Re: Rotating an array.
Message-Id: <360e943d.13307584@news.nyu.edu>
On Wed, 23 Sep 1998 17:01:27 +0200, Casper Kvan Clausen <ckc@dmi.dk>
wrote:
>Hiya all.
>
>I'm mainly asking this to see what sorts of strange and twisted answers
>you guys can come up with, since, given the fickle nature of Usenet, I
>doubt any answers will appear in time to make into my code.
>
>The problem is this: Given an array A of n elements, how do you most
>efficiently construct a new array B containing the same elements, but
>rotated so that B[0] = A[n-m], B[1] = A[n-m+1] ... B[m] = A[n]?
If I understand correctly, you are trying to do this.
$B[ $x ] = $A[ $n - $m + $x] where 0 <= $x <= $m
Then, it is impossible to have $B[ $m ] = $A [ $n ] unless $m == $n in
which case @B = reverse(@A)..
Describe your problem correctly!
>I am currently using splice() as follows:
>
>#!/usr/bin/perl -w
>
>@words = qw(one two three four five);
>
>$rot = 2; @a = @words;
>
>@b = splice(@a,$rot,$#a - $rot + 1);
>splice (@b,$#b + 1,0,@a);
>
>print "Original order:\n\n";
>print join (' ',@words) . "\n\n";
>print "New (fnord World fnord) Order:\n\n";
>print join (' ',@b) . "\n";
>
>__END__
now, i understand it... you want to divide @A into two and swap
them... why go through all these troubles??? And you should use
"use strict;"
#!/usr/bin/perl -w
use strict;
my @words = qw(one two three four five);
my $rot = 2; # indiciating you want the first two elements
# to be at the end of new array;
my @confused_words = (@words[$rot..$#words],
@words[0..$rot - 1]);
print join (" ", @confused_words), "\n";
This should do it! I don't know how much faster it would be compared
to your code but it should be faster b/c it does not have to copy
"@words" into "@a". Plus it's easier to understand than using
"splice". Personally, I usually don't use "splice".
Use Benchmark module to find it.
Cios
mj lee
>
>I know, however, that all y'all's twisted minds can come up with some much
>more interesting ways of doing things - some of which might even be more
>efficient. Looking forward to seeing them.
>
>Kvan.
>
>-------Casper Kvan Clausen------ | 'Political correctness: Has it had
>----------<ckc@dmi.dk>---------- | its day? We interview a leading
> Lokal 544 | poof.'
>I do not speak for DMI, just me. | - Mel Smith.
>
------------------------------
Date: Wed, 23 Sep 1998 18:45:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Rotating an array.
Message-Id: <MPG.107343f66c8b26a29897b8@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <360e943d.13307584@news.nyu.edu> on Thu, 24 Sep 1998 00:42:09
GMT, MJ Lee <mjlee@amherst.edu> says...
> On Wed, 23 Sep 1998 17:01:27 +0200, Casper Kvan Clausen <ckc@dmi.dk>
> wrote:
...
> >The problem is this: Given an array A of n elements, how do you most
> >efficiently construct a new array B containing the same elements, but
> >rotated so that B[0] = A[n-m], B[1] = A[n-m+1] ... B[m] = A[n]?
>
> If I understand correctly, you are trying to do this.
>
> $B[ $x ] = $A[ $n - $m + $x] where 0 <= $x <= $m
>
> Then, it is impossible to have $B[ $m ] = $A [ $n ] unless $m == $n in
> which case @B = reverse(@A)..
Why? All it needs is $m <= $n to get a slice of the array. And if $m ==
$n, the result is
@B = @A;
not reversed.
...
> my @confused_words = (@words[$rot..$#words],
> @words[0..$rot - 1]);
>
> print join (" ", @confused_words), "\n";
>
> This should do it! I don't know how much faster it would be compared
> to your code but it should be faster b/c it does not have to copy
> "@words" into "@a". Plus it's easier to understand than using
> "splice". Personally, I usually don't use "splice".
>
> Use Benchmark module to find it.
That has been done already. See my post earlier today and Larry Wall's
observation about it.
I measured more than a decimal order of magnitude difference in
performance. Maybe you *should* use "splice". :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 23 Sep 1998 15:42:00 -1000
From: "Michael Ching" <m_ching@hotmail.com>
Subject: Re: sending email attachments using just perl?
Message-Id: <360979c4.0@news.hawaii.rr.com>
look into the MIME module. I think it can do this- if not, an email, even
with an attachment is just text; just formatting is the problem. so yes, it
is possible.
tim pickup wrote in message <36096761.31631561@news.demon.co.uk>...
>I am writnig a perl script which sends an email built up on an html
>form on a browser. Similar to the service yahoo/hotmail provides.
>
>The problem is I want to attach a local file to the email message.
>I think yahoo.com uses java to encode the file and attach it.
>Is there a way of doing this directly using just perl?
>
>Thanks
>
>tim
------------------------------
Date: Wed, 23 Sep 1998 19:15:32 -0400
From: nospam@wam.umd.edu (Vikram Pant)
Subject: Sorting Array Of Directories via ABC, not date...
Message-Id: <MPG.10734b2291b9063098969c@news.wam.umd.edu>
I'm reading in all the directory names (~320) and putting them in an
index HTML page. The problem is that they are not in ABC order, but
rather when I wrote them order.
I call the directories into an array like such:
opendir(ALL, "$RootDir");
@All_Dir = readdir(ALL);
closedir(ALL);
And when I print out the array, it appears as the page below.
http://midifest.com/MIDIFest/PopRock/
As you see, if you visit, the Names are not in ABC order, but date order.
I was wondering if a Perl function existed that sorts arrays by ABC?
Thanks,
Vikram Pant
------------------------------
Date: Wed, 23 Sep 1998 17:35:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting Array Of Directories via ABC, not date...
Message-Id: <MPG.10733393e42bcb059897b7@nntp.hpl.hp.com>
In article <MPG.10734b2291b9063098969c@news.wam.umd.edu> on Wed, 23 Sep
1998 19:15:32 -0400, Vikram Pant <nospam@wam.umd.edu> says...
...
> I was wondering if a Perl function existed that sorts arrays by ABC?
Yes, there is. Its name is 'sort' (how's that for a surprise?).
Do `perldoc -f sort` and look at the examples.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3807
**************************************