[18749] in Perl-Users-Digest
Perl-Users Digest, Issue: 917 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 16 18:16:06 2001
Date: Wed, 16 May 2001 15:15:27 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990051327-v10-i917@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 16 May 2001 Volume: 10 Number: 917
Today's topics:
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <newspost@coppit.org>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <newspost@coppit.org>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <newspost@coppit.org>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <godzilla@stomp.stomp.tokyo>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <godzilla@stomp.stomp.tokyo>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <newspost@coppit.org>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Mark Jason Dominus)
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (E.Chang)
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Tad McClellan)
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <AgitatorsBand@yahoo.com>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <mischief@velma.motion.net>
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Tad McClellan)
Random Numbers Script <saras@gj.net>
Re: Random Numbers Script (Eric Bohlman)
Re: regExp question (Anno Siegel)
Re: regExp question <uri@sysarch.com>
Re: regExp question (Randal L. Schwartz)
Re: regExp question (Craig Berry)
Re: regExp question (Craig Berry)
Simple sorting problem <yf32@cornell.edu>
Re: Simple sorting problem <krahnj@acm.org>
Re: Stumped on $?, duplicate output (Mark Jason Dominus)
Re: Taint <mischief@velma.motion.net>
tie, FETCH and list context (Dave Murray-Rust)
Re: tie, FETCH and list context nobull@mail.com
Re: tie, FETCH and list context <joe+usenet@sunstarsys.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 May 2001 14:45:14 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Pine.SUN.4.33.0105161426110.3295-100000@mamba.cs.Virginia.EDU>
On Tue, 15 May 2001, Godzilla! wrote:
> Nor do you equal my talent with language, in both reading and writing.
... and then you said ...
> "Reality is a harsh mistress, few are willing to bed."
Nice comma splice.
It's wise to show a touch of humility at times to avoid such
embarrassment.
--
David
------------------------------
Date: Wed, 16 May 2001 14:49:29 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Pine.SUN.4.33.0105161447410.3610-100000@mamba.cs.Virginia.EDU>
On Wed, 16 May 2001, E.Chang wrote:
> mjd@plover.com (Mark Jason Dominus) wrote in
> <3b01c0f0.8f3$c4@news.op.net>:
> >I agree. 'Must' is inappropriate, and only serves to make the
> >authors look foolish.
>
> I like the the guidelines in general, but also find "must" too strong.
> A heading such as "Things to do *before* you post a question to
> comp.lang.perl.misc" would get the point across without the "Achtung!"
> tone.
Agreed. At times this newsgroup seems (to me at least) a bit elitist,
and such "commandments" only enforce that. We don't want to discourage
people needlessly.
--
David
------------------------------
Date: Wed, 16 May 2001 14:56:41 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Pine.SUN.4.33.0105161450460.3610-100000@mamba.cs.Virginia.EDU>
On 15 May 2001, Andrew J. Perrin wrote:
> David Coppit <newspost@coppit.org> writes:
>
> > On Tue, 15 May 2001, Godzilla! wrote:
> > > Possibly you face challenges in reading comprehension or, are being
> > > masquer deceitful?
> >
> > Have I done something to deserve this comment? I try to treat other
> > people with respect, and would appreciate the same unless I
> > demonstrate myself unworthy of it.
>
> It's definitely a mistake to be hurt or insulted by something
> Godzilla! spews - just say a little prayer of thanks that you don't
> know her/him/it in any context other than 'net. S/he/it enjoys trolling.
In fact, I'm not all that insulted. I was trying to make a poignant
point.
Typically I just killfile trolls, but unfortunately (fortunately?)
half the time 'zilla has good stuff to say. The last post I read
didn't even have a hint of troll. ;)
--
David
------------------------------
Date: Wed, 16 May 2001 12:03:13 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3B02CEF1.86752DE3@stomp.stomp.tokyo>
David Coppit wrote:
> Godzilla! wrote:
> > Nor do you equal my talent with language, in both reading and writing.
> ... and then you said ...
> > "Reality is a harsh mistress, few are willing to bed."
> Nice comma splice.
> It's wise to show a touch of humility at times to avoid such
> embarrassment.
It is clear your skill level in language usage
would be categorized as "functional illiterate."
This is, of course, a relative reflection upon
your overall intelligence.
"Vocabulary is the yardstick of knowledge."
Godzilla!
------------------------------
Date: Wed, 16 May 2001 12:09:51 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3B02D07F.AECA5A9E@stomp.stomp.tokyo>
David Coppit wrote:
> Andrew J. Perrin wrote:
> > David Coppit wrote:
> > > Godzilla! wrote:
> > > > Possibly you face challenges in reading comprehension or, are being
> > > > masquer deceitful?
> > > Have I done something to deserve this comment? I try to treat other
> > > people with respect, and would appreciate the same unless I
> > > demonstrate myself unworthy of it.
(unnoted snippage, context deliberately changed)
> > It's definitely a mistake to be hurt or insulted by something
> > Godzilla! spews - just say a little prayer of thanks that you don't
> > know her/him/it in any context other than 'net. S/he/it enjoys trolling.
> In fact, I'm not all that insulted. I was trying to make a poignant
> point.
> Typically I just killfile trolls, but unfortunately (fortunately?)
> half the time 'zilla has good stuff to say. The last post I read
> didn't even have a hint of troll. ;)
Why do you persist in posting troll articles directed
solely at me and no other?
Godzilla!
------------------------------
Date: Wed, 16 May 2001 15:03:31 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Pine.SUN.4.33.0105161457380.3610-100000@mamba.cs.Virginia.EDU>
On Wed, 16 May 2001, Steven Smolinski wrote:
> And so it is here. *If* you want Tad to help (any many other good
> people besides him) you *must* check the docs first. That's all I took
> it to mean, and find it reasonable (and true) as said.
>
> People who bristle at rules just because they're rules will always hate
> these conditional absolutes. And if you word the rule so as to make it
> seem optional, people will think the rule itself is optional. But it is
> not. How optional is it that, say, Abigail will explain a FAQ to some
> newbie who couldn't be bothered to grep through the pod?
Let's face it, the rule is optional. You can't force anyone to read
the FAQ before posting. You also can't assume that someone will even
see the rule before posting.
Maybe the preface of the document could just say that some people have
the policy of not answering FAQs in order to better use their precious
time. Further, an answer can often be found more quickly by following
the rules. Heck, I know that the task of producing a concise program
has often shown me the solution.
--
David
------------------------------
Date: Wed, 16 May 2001 19:18:12 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3b02d270.216f$292@news.op.net>
In article <slrn9g4433.90p.bernard.el-hagin@gdndev25.lido-tech>,
Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>You don't seem to understand that the 'must' means 'if you want expert
>advice from some of the best Perl programmers in the world you must'
If that's what it means, then it should be removed because it is wrong.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Wed, 16 May 2001 19:19:15 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Xns90A39C3DD4847echangnetstormnet@207.106.92.86>
Henry Hartley <hartleh1@westat.com> wrote in
<3B02B79F.271251E2@westat.com>:
>"E.Chang" wrote:
>>
>> mjd@plover.com (Mark Jason Dominus) wrote in
>> <3b01c0f0.8f3$c4@news.op.net>:
>>
>>> In article <9dppmc$j5l$1@news.orst.edu>,
>>> John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
>>>
>>>> Amost all of this is very good advice. I've only got a problem
>>>> with the imperatives that are being used.
>>>
>>> I agree. 'Must' is inappropriate, and only serves to make the
>>> authors look foolish.
>>
>> I like the the guidelines in general, but also find "must" too
>> strong. A heading such as "Things to do *before* you post a
>> question to comp.lang.perl.misc" would get the point across
>> without the "Achtung!" tone.
>
>So the authors must not use that word? Or perhaps they should not?
>
As I see it, neither of the above. Ultimately, the writer can, may, and
presumably will do what he decides reflects the views of the group, and
I for one will accept that. The author stated early on that "This is
supposed to be (as close as is practicable) the concensus of the
group's participants..." Achieving consensus commonly involves
expressing opinions and trying to find a common ground. I have no
authority to prescribe, merely to express a personal opinion
(preferably just once).
--
EBC
------------------------------
Date: Wed, 16 May 2001 14:44:07 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <slrn9g5ijn.nqi.tadmc@tadmc26.august.net>
Steven Smolinski <steven.smolinski@sympatico.ca> wrote:
>Mark Jason Dominus <mjd@plover.com> wrote:
>> John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
>> >Amost all of this is very good advice. I've only got a problem with the
>> >imperatives that are being used.
>>
>> I agree. 'Must' is inappropriate, and only serves to make the authors
>> look foolish.
>
>I don't think it makes the authors look foolish if they use the term
>properly, i.e., within a conditional. "*If* you wish to retain the interest
>of the regulars, you must do x."
That last sentence could be a paraphrase of what I'll change/add
in rev 1.2.
>And so it is here. *If* you want Tad to help (any many other good
>people besides him) you *must* check the docs first. That's all I took
>it to mean, and find it reasonable (and true) as said.
^^^^^^^
I think there is plenty of room to say it more clearly, so I'll
attempt that in the next revision. Please stand by...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 16 May 2001 21:11:12 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <Q1CM6.857$du2.78315@news.shore.net>
Alan J. Flavell <flavell@mail.cern.ch> wrote:
: On Wed, 16 May 2001, Scratchie wrote:
:> The more people discover bad code in Usenet newsgroups,
:> the more likely they are to figure out that newsgroups are not necessarily
:> the first place one should look for help with simple problems.
: It would seem perverse to deliberately post bad code in the hope that
: it would discourge them from pestering the experts with simple
: problems.
Where did I suggest that?
: Or what _is_ your concrete proposal at this point?
My suggestion was that experts who are "too busy" to answer FAQs simply
ignore them rather than writing snide put-downs.
--Art
------------------------------
Date: Wed, 16 May 2001 21:37:17 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <tg5sodi7rbnj8c@corp.supernews.com>
Scratchie <AgitatorsBand@yahoo.com> wrote:
> Alan J. Flavell <flavell@mail.cern.ch> wrote:
> : On Wed, 16 May 2001, Scratchie wrote:
> :> The more people discover bad code in Usenet newsgroups,
> :> the more likely they are to figure out that newsgroups are not necessarily
> :> the first place one should look for help with simple problems.
> : It would seem perverse to deliberately post bad code in the hope that
> : it would discourge them from pestering the experts with simple
> : problems.
> Where did I suggest that?
> : Or what _is_ your concrete proposal at this point?
> My suggestion was that experts who are "too busy" to answer FAQs simply
> ignore them rather than writing snide put-downs.
So perhaps one of the things in those guidelines should be:
Things you Must NOT do:
reply to FAQs with snide putdowns. We are trying to
get along here. Please be polite, even when correcting
someone for lack of compliance with this document.
Chris
--
The purpose of a language is not to help you learn the
language, but to help you learn other things by using the
language. --Larry Wall, The Culture of Perl, August 1997
------------------------------
Date: Wed, 16 May 2001 17:08:40 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <slrn9g5r2n.nun.tadmc@tadmc26.august.net>
Mark Jason Dominus <mjd@plover.com> wrote:
>In article <slrn9g4433.90p.bernard.el-hagin@gdndev25.lido-tech>,
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>>You don't seem to understand that the 'must' means 'if you want expert
>>advice from some of the best Perl programmers in the world you must'
^^^^
>If that's what it means, then it should be removed because it is wrong.
I don't see that it is wrong. What is wrong about it?
"some" implies "more than one", it does not imply "all".
( good thing, because "most" of the best Perl programmers aren't
here slogging through this low S/N resource anyway.
)
I know for a fact (I have scorefile fragments from each) that
two such programmers[1] score down for many of the points covered
in these guidelines.
Those points covered in the "must" section are the ones
with the highest negative weight relative to the bulk of the
other things they score down for, which suggested to me that
they be highlighted in some fashion.
[1] assuming that folks named in the Camel3 are in the set
of "best Perl programmers".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 16 May 2001 12:33:40 -0600
From: "sas" <saras@gj.net>
Subject: Random Numbers Script
Message-Id: <3b02c854@news.gj.net>
Does anyone have a script that will generate random numbers? Someone told me
I could do it with Perl but I don't know where to start. It must be a 5
digit random number which will be associated with a specific name, (an "ID"
number), I want to check against a log file to be sure the number hasn't
been used already and then add the number and associated name to that log
file. Any help will be greatly appreciated.
Thanks
sas
saras@gj.net
------------------------------
Date: 16 May 2001 19:02:47 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Random Numbers Script
Message-Id: <9duisn$ert$4@bob.news.rcn.net>
sas <saras@gj.net> wrote:
> Does anyone have a script that will generate random numbers? Someone told me
> I could do it with Perl but I don't know where to start. It must be a 5
> digit random number which will be associated with a specific name, (an "ID"
> number), I want to check against a log file to be sure the number hasn't
> been used already and then add the number and associated name to that log
> file. Any help will be greatly appreciated.
Try breaking your problem up into little pieces and solving the
individually. First, you want to generate random numbers. If you search
Perl's documentation for "random," you'll find a function which generates
random numbers. When you read the documentation for it, you'll find that
it lets you specify the range of numbers to be generated, which is half of
the next piece. The other half of the next piece is making sure the
number is always five digits long; this is a case where There's More Than
One Way To Do It (TMTOWTDI). One of those ways involves the sprintf()
function, so read up on sprintf() in the perlfunc document. The logging
is probably best handled by what's called a "tied database hash"; read up
on tie() in perlfunc.
------------------------------
Date: 16 May 2001 18:23:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regExp question
Message-Id: <9dugjh$5r$1@mamenchi.zrz.TU-Berlin.DE>
According to Jay Tilton <tiltonj@erols.com>:
> On Wed, 16 May 2001 14:39:01 +0200, "Peter Søgaard"
> <peter.sogaard@tjgroup.com> wrote:
>
> >Say i have a string:
> >$text = "blablabla at monday and blablabla at tuesday wednesday and thursday
> >blablabla";
> >
> >then i want to translate all the days in $str to "mon","tue" etc.
> >
> >I guess i need to make to lists...one the @seachList =
> >("monday","tuesday",etc) and the other the @translationList =
> >("mon","tue",etc)
> >
> >but how do i use these 2 lists in my regexp?
>
> Any time you're thinking of creating two lists with a one-to-one
> relationship between elements, you're better off using a hash.
>
> my %substitutions = (
> Monday => 'Mon',
> Tuesday => 'Tue',
> Wednesday => 'Wed',
> Thursday => 'Thu',
> Friday => 'Fri',
> Saturday => 'Sat',
> Sunday => 'Sun',
> );
>
> $text =~ s/$_/$substitutions{$_}/ig foreach keys %substitutions;
>
> But that may be a bit of overkill for this particular problem.
> It can be done in a single statement.
>
> $text =~ s/\b(mon|tue|wed|thu|fri|sat|sun)\w*day/$1/ig;
Fair enough, but this only works because the English language currently
doesn't possess[1] a word like "Montyday", which would become "Mon".
It would also shorten "Mondays" to "Mons", whether this is desired or
not, though this can be controlled by insertion of the appropriate \b's.
Granted, for some classes of text this may be exactly the thing to do,
but for a more maintainable and generalizable approach I'd revive the
hash, but without need of a loop (or the /e modifier):
$text =~
s[\b(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\b]
[$substitutions{ $1}]g;
This allows only exact matches. It doesn't even allow an /i modifier,
unless we prepare the hash first with something like
$substitutions{ lc $_} = lc $substitutions{ $_} for keys %substitutions;
With or without this preparation, you could get fancy and build the
regex on the fly:
$text =~ s[\b(${ \ join( '|', keys %substitutions)})\b]
[$substitutions{ $1}]g;
In a less radical approach, you might want to save the regex in one
place and use it in one or more others:
my $re = qr/\b(${ \ join( '|', keys %substitutions)})\b/;
...
$text =~ s/$re/$substitutions{ $1}/;
Anno
[1] egrep -i '(mon|tue|wed|thu|fri|sat|sun).*day' /usr/dict/words
comes up with only the usual suspects.
------------------------------
Date: Wed, 16 May 2001 18:44:33 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: regExp question
Message-Id: <x7r8xp8771.fsf@home.sysarch.com>
>>>>> "CB" == Craig Berry <cberry@cinenet.net> writes:
CB> my @daynames = qw(monday tuesday wednesday thursday friday
CB> saturday sunday);
CB> my %trans;
CB> @trans{@daynames} = map { substr($_, 0, 3) } @daynames;
my %trans = map { $_, substr($_, 0, 3) } @daynames ;
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 16 May 2001 11:51:14 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: regExp question
Message-Id: <m1pud9dt5p.fsf@halfdome.holdit.com>
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
>>>>> "CB" == Craig Berry <cberry@cinenet.net> writes:
CB> my @daynames = qw(monday tuesday wednesday thursday friday
CB> saturday sunday);
CB> my %trans;
CB> @trans{@daynames} = map { substr($_, 0, 3) } @daynames;
Uri> my %trans = map { $_, substr($_, 0, 3) } @daynames ;
my %trans = map /((...).*)/, @daynames;
:-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 16 May 2001 21:35:45 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regExp question
Message-Id: <tg5slhifsn6o72@corp.supernews.com>
Uri Guttman (uri@sysarch.com) wrote:
: >>>>> "CB" == Craig Berry <cberry@cinenet.net> writes:
:
: CB> my @daynames = qw(monday tuesday wednesday thursday friday
: CB> saturday sunday);
:
: CB> my %trans;
: CB> @trans{@daynames} = map { substr($_, 0, 3) } @daynames;
:
: my %trans = map { $_, substr($_, 0, 3) } @daynames ;
That is seriously nice, and I'd never thought of doing it that way.
Thanks!
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Wed, 16 May 2001 21:37:22 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regExp question
Message-Id: <tg5soitdg58f8f@corp.supernews.com>
Randal L. Schwartz (merlyn@stonehenge.com) wrote:
: Uri> my %trans = map { $_, substr($_, 0, 3) } @daynames ;
:
: my %trans = map /((...).*)/, @daynames;
I know nothing about perl. :P
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Wed, 16 May 2001 15:26:35 -0400
From: Young Chi-Yeung Fan <yf32@cornell.edu>
Subject: Simple sorting problem
Message-Id: <3B02D46B.6A27560C@cornell.edu>
Hi,
I'm trying to sort key-value pairs read in from a DBM file. The keys
are:
1, 2, 3, ..., 14, 15, 16, A, B
Using this loop:
for $trip (sort { $a <=> $b } keys %DATA) { ... }
I get this sorted result:
B, A, 1, 2, ..., 15, 16
Using this loop:
for $tripnum (sort keys %VM) { ... }
I get this sorted result:
1, 10, 11, ..., 15, 16, 2, 3, 4, ... , 8, 9, A, B
What I want is this:
1, 2, 3, ..., 14, 15, 16, A, B
What do I have to do to get that result? Thanks a lot for your help!
Young
------------------------------
Date: Wed, 16 May 2001 20:42:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Simple sorting problem
Message-Id: <3B02E65C.A139749B@acm.org>
Young Chi-Yeung Fan wrote:
>
> I'm trying to sort key-value pairs read in from a DBM file. The keys
> are:
> 1, 2, 3, ..., 14, 15, 16, A, B
>
> Using this loop:
>
> for $trip (sort { $a <=> $b } keys %DATA) { ... }
>
> I get this sorted result:
> B, A, 1, 2, ..., 15, 16
>
> Using this loop:
>
> for $tripnum (sort keys %VM) { ... }
>
> I get this sorted result:
> 1, 10, 11, ..., 15, 16, 2, 3, 4, ... , 8, 9, A, B
>
> What I want is this:
> 1, 2, 3, ..., 14, 15, 16, A, B
>
> What do I have to do to get that result? Thanks a lot for your help!
Here is one way to do it:
#!/usr/bin/perl -w
use strict;
my @x = ( 1 .. 16, 'A', 'B' );
print "@x\n";
my %y = map { $_, ++$a } @x;
shuffle( \@x );
print "@x\n";
my @z = sort { $y{$a} <=> $y{$b} } @x;
print "@z\n";
# fisher_yates_shuffle( \@array ) :
# generate a random permutation of @array in place
sub shuffle {
my $array = shift;
my $i;
for ( $i = @$array; --$i; ) {
my $j = int rand( $i + 1 );
next if $i == $j;
@$array[ $i, $j ] = @$array[ $j, $i ];
}
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 16 May 2001 19:27:32 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Stumped on $?, duplicate output
Message-Id: <3b02d4a4.21ae$11c@news.op.net>
In article <hg15gtkckgq0ccf2ri8jl87fndrfs608eo@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Mr. Sunray wrote:
>
>> print $?, "\n"; # prints -1
>
>-1 is a dummy value which indicates that this feature is not properly
>working.
Does your explanation have any connection with reality, or is it just
the product of your imagination? I suspect the latter.
% perl -le 'system("exit 255"); print $?'
-1
Here $? contains -1, and yet the feature is properly working. Nothing
went wrong when my perl was built.
> Perhaps something went wrong when your perl was built.
Or perhaps the program (which we only saw a fragment of) has a bug.
Looking for a compiler bug is the strategy of LAST resort.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Wed, 16 May 2001 21:53:10 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Taint
Message-Id: <tg5tm6219h8pa5@corp.supernews.com>
Dodger <dodger@necrosoft.net> wrote:
> "Uri Guttman" <uri@sysarch.com> wrote in message
> news:x7pudd9i61.fsf@home.sysarch.com...
>> then what is the point of enabling taint to begin with? you logic is
>> backwards. if you don't care about security, then don't taint. if you
>> taint, you just don't do unsecure untaint hacks.
> When you have no choice, such as whilst in a setuid script.
If I'm running setuid, you'd better believe I want to know
what it is I'm doing with which datum. The higher the
program's access to the system, the _more_ you want the
protection of tainting data.
There are secure ways to untaint data. You don't have to
rely on a completely unsafe way to do it in order to use
the value of a variable.
Chris
--
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: Wed, 16 May 2001 18:33:20 +0100
From: dave@mo-seph.com (Dave Murray-Rust)
Subject: tie, FETCH and list context
Message-Id: <slrn9g5ef0.d14.dave@flop.localnet>
Hiya,
I'm trying to write a TIEHASH class which will behave like a normal
hash, except when a value would be overwritten. In this situation I
want it to create an array, and push the old and new values onto it.
If the value is already an array, it should simply push the new value
onto the end. This part of things is OK. (code follows at end. Note: I
have bounded the problem to only accept values which are not
references)
The part with which I am having trouble with is the return value;
Ideally I would like to:
- If the value is an array, return a list of the values in it, so that
in scalar context it works as a LIFO, but if the caller can handle
lists it will get all the values.
- If the value is a scalar, simply return a scalar.
The plan is to have something which works much like a hash, but can
return the old values on request - I guess it's like HashHistory, but
a bit more transparent. The _specific_ problem I'm having is that
I cannot return a list from my FETCH subroutine. Also, wantarray
always returns false inside FETCH. I can see how forcing FETCH into
scalar context would make sense, but I can't find any documentation
about this (apart from a few random references in web searching).
So a) Is it FETCH always in scalar context?
b) Is there any cunning workaround?
The more general context is dealing with CGI <hangs head in shame/> and
Apache/mod_perl. I have a checkbox group which is going to return
multiple values for the same key. If I assign the $r->content to a
hash, these values overwrite each other, which I don't want.
Any help greatly appreciated,
Dave
__BEGIN__MODULE__
#ListHash.pm
# A class which provides multiple values for hashes
# It does this by overriding STORE, so that:
# a) If the key does not exist, it adds it
# b) If the key exists, and is a scalar ref, it
# takes the value, pushes it onto an array, and
# then pushes the new value on;
# c) If the key exists and is a list
package ListHash;
require Tie::Hash;
use strict;
use warnings;
our @ISA = qw(Tie::StdHash);
sub STORE
{
my( $self, $key, $value ) = @_;
if( ref( $value ) )
{
warn "Cannon store references in a ListHash!\n" .
"( you tried to store a " . ref( $value ) . " )\n";
return;
}
if( !exists $self->{ $key } )
{
$self->{ $key } = $value;
}
elsif( !ref( $self->{ $key } ) )
{
my $firstVal = $self->{ $key };
$self->{ $key } = [ $firstVal, $value ];
}
elsif( ref( $self->{ $key } ) eq 'ARRAY' )
{
push @{ $self->{ $key } }, $value;
}
}
sub FETCH
{
my( $self, $key ) = @_;
warn "Fetching key: $key\n";
if( !ref( $self->{ $key } ) )
{
return $self->{ $key };
}
else
{
if( wantarray )
{
return @{ $self->{ $key } }
}
else
{
return $self->{ $key }->[ -1 ];
}
}
}
1;
__END_MODULE__
__BEGIN__TESTSCRIPT__
#!/usr/bin/perl -wI.
use strict;
use ListHash;
my %hash;
my $obj = tie %hash, 'ListHash';
$hash{ a } = "Aaay";
$hash{ a } = "Beee";
my @b = $hash{ a };
print @b;
__END__TESTSCRIPT__
--
------------------------------
Date: 16 May 2001 20:39:44 +0100
From: nobull@mail.com
Subject: Re: tie, FETCH and list context
Message-Id: <u9lmnxulq7.fsf@wcl-l.bham.ac.uk>
dave@mo-seph.com (Dave Murray-Rust) writes:
> The _specific_ problem I'm having is that I cannot return a list
> from my FETCH subroutine. Also, wantarray always returns false
> inside FETCH. I can see how forcing FETCH into scalar context would
> make sense, but I can't find any documentation about this (apart
> from a few random references in web searching).
It not only "would make sense" but is IMHO clearly inevitable.
The syntax that effectively expands to
scalar(tied(%foo)->FETCH('bar')) is $foo{bar} and the $ in the front
means this is a scalar expression.
> So a) Is it FETCH always in scalar context?
Yes.
> b) Is there any cunning workaround?
Not that I can think of.
You can, of course, write tied(%foo)->FETCH('bar') explicitly. But
I'd not really consider that cunning.
> The more general context is dealing with CGI <hangs head in shame/> and
> Apache/mod_perl. I have a checkbox group which is going to return
> multiple values for the same key. If I assign the $r->content to a
> hash, these values overwrite each other, which I don't want.
Again you can say tied(%foo)->STORE('bar',LIST);
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 16 May 2001 17:03:04 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: tie, FETCH and list context
Message-Id: <m3vgn1ypkn.fsf@mumonkan.sunstarsys.com>
dave@mo-seph.com (Dave Murray-Rust) writes:
[... about tied hashes ...]
> So a) Is it FETCH always in scalar context?
Pretty much- and it makes sense to do so. Otherwise stuff like
each() and values() could fail to work as documented.
> b) Is there any cunning workaround?
Not really, but by calling FETCH directly you can place it in any
context you wish. Anyway, for tied hashes it's considerably faster
(albeit uglier) to use something like this
tied(%hash) -> FETCH('foo')
instead of this
$hash{foo}
I have no idea why this is so.
> The more general context is dealing with CGI <hangs head in shame/> and
> Apache/mod_perl. I have a checkbox group which is going to return
> multiple values for the same key. If I assign the $r->content to a
Why are you parsing the CGI parameters yourself? Apache::Request [1]
will do this for you, and calling
my $apr = Apache::Request -> new;
my @vals = $apr -> param('checkbox_key');
does exactly what you seem to want. Note that this is the same as
my $hash_ref = $apr -> param; # ref to tied Apache::Table object
my @vals = $hash_ref -> FETCH('checkbox_key');
The author of Apache::Table had to confront this same issue when making
HTTP headers available via a (multivalued) tied Perl hash. Note that
Apache::Table is part of the mod_perl core, and uses case-insensitive
hash keys as well.
[1] sorry for shilling a package that I work on, but IMO towing the
CGI.pm party line isn't so wonderful in a mod_perl environment.
Besides, we're trying to get a new release together and more beta
testers are needed. Any volunteers? :-)
--
Joe Schaefer "Language is the dress of thought."
-- Samuel Johnson
------------------------------
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.
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 917
**************************************