[25309] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7554 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 22 14:10:43 2004

Date: Wed, 22 Dec 2004 11:10:10 -0800 (PST)
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, 22 Dec 2004     Volume: 10 Number: 7554

Today's topics:
    Re: Is zero even or odd? <paul@scazon.com>
    Re: Is zero even or odd? <nowhere@nowhere.net>
    Re: Is zero even or odd? <dak@gnu.org>
    Re: Is zero even or odd? <do-not-use@invalid.net>
    Re: Is zero even or odd? <shawn.corey@sympatico.ca>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <jfields@austininstruments.com>
    Re: Is zero even or odd? <a.newmane.remove@eastcoastcz.com>
    Re: Is zero even or odd? <salesEXTRACT@anasoft.co.uk>
    Re: Is zero even or odd? <nowhere@nowhere.net>
        Output pipes <kimgh@pacbell.net>
    Re: Output pipes <jgibson@mail.arc.nasa.gov>
        Regexp golf question <AaronJSherman@gmail.com>
    Re: Regexp golf question (Anno Siegel)
    Re: Regexp golf question <AaronJSherman@gmail.com>
        retrieving Hash elements <nospam@nospam.com>
    Re: retrieving Hash elements <x3v0-usenet@yahoo.com>
    Re: retrieving Hash elements <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 22 Dec 2004 16:06:54 +0000
From: Paul Burke <paul@scazon.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tkpvF3p9cm2U1@individual.net>

Kevin Aylward wrote:

> 
> "Warden of the King's Ale"
> 

You wish! It's more like one of these almost production- line 
mix-and-match names that the Anglo-Saxons went in for, you know, 
ethelfrith, ethelred, brithnoth, brithelm etc. etc. I'd guess it means 
something like "noble guard". They quite often got abraded over time- 
Wolverton being Wulfheardestun or similar, so the change in sound isn't 
surprising. Put it down to the Great Bowel Shift.

Paul Burke


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

Date: Wed, 22 Dec 2004 11:15:10 -0500
From: "robert j. kolker" <nowhere@nowhere.net>
Subject: Re: Is zero even or odd?
Message-Id: <32tksiF3pqp1eU1@individual.net>



Arndt Jonasson wrote:
> 
> And in computing, there are representations of integers in binary that
> have both a 0 and a -0. Of floating-point too, for that matter.

Forr that matters not. Finite representations of numbers are an artifact 
of the computer memory and have little to do with the numbers themselves.

Bob Kolker


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

Date: Wed, 22 Dec 2004 17:18:49 +0100
From: David Kastrup <dak@gnu.org>
Subject: Re: Is zero even or odd?
Message-Id: <x53bxyjogm.fsf@lola.goethe.zz>

"Kevin Aylward" <salesEXTRACT@anasoft.co.uk> writes:

> vonroach wrote:
>> On Mon, 20 Dec 2004 14:34:03 -0000, BB <BB@BB.BB> wrote:
>>
>>> The divisor would have to be something smaller than 0 like -2.
>>> Therefore zero is both even and negative.
>>
>> Whoa!  A new concept: -0.  Let's make up some other numbers. I suggest
>> wizzad and fugawe. I'd have suggested Arunda, but I believe some
>> obscure African group already uses that in their alphabet.
>
> -0 often/usually signifies a limit approaching from the negative 
> direction.

No.  One writes 0- for that.  As in 

lim     exp(1/x) = 0
x -> 0-

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


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

Date: 22 Dec 2004 17:26:05 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Is zero even or odd?
Message-Id: <yzd1xdijo4i.fsf@invalid.net>


"robert j. kolker" <nowhere@nowhere.net> writes:
> Arndt Jonasson wrote:
> > And in computing, there are representations of integers in binary
> > that
> > have both a 0 and a -0. Of floating-point too, for that matter.
> 
> Forr that matters not. Finite representations of numbers are an
> artifact of the computer memory and have little to do with the numbers
> themselves.

You may not have noticed, but this discussion has already entered the
free association phase.

My CD player also has a -0. When it shows the number of seconds played
on a track, it sometimes starts with a negative number and goes -2 -1
-0 0 1 2 ...  There is a full second between -0 and 0.
(sci.electronics.design, why not.)


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

Date: Wed, 22 Dec 2004 12:07:32 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Is zero even or odd?
Message-Id: <pQhyd.21850$GK5.1173942@news20.bellglobal.com>

vonroach wrote:
>  Then infinity is undefined?  

Infinity is defined but not a number.

infinity = limit(x->0) 1/x^2

    --- Shawn


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

Date: Wed, 22 Dec 2004 09:26:48 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tp6mF3rab8bU1@individual.net>

Fred Bloggs wrote:
> Kevin Aylward wrote:
>> Fred Bloggs wrote:
>>
>>> Alfred Z. Newmane wrote:
>>>
>>>> Nicholas O. Lindan wrote:
>>>>
>>>>
>>>>> "John Sefton" <john@petcom.com> wrote
>>>>>
>>>>>
>>>>>
>>>>>> 0 can't be divided by itself,
>>>>>
>>>>> Sure it can: 0 / 0 = 0 * (1 / 0) = 0 * infinity = 1
>>>>>
>>>>> It works if the only three numbers in the universe are
>>>>> 0, 1, and infinity -- A number system that seems very
>>>>> suited to usenet.
>>>>
>>>>
>>>> Except for the fact that: 0 / 0 = undefined
>>>>
>>>> Or actually more correct: n / 0 = undefined
>>>>
>>>>
>>>
>>> 0/0={ SET OF ALL INTEGERS }
>>
>>
>> No.
>>
>>
>>> n/0= NULL SET  for n<>0
>>>
>>> It is very well-defined.
>>
>>
>> No it isnt.
>>
>> Kevin Aylward
>
> You apparently have stumbled on something else you know damn little
> about. In case you need help with this , you might note that "/" is
> NOT an operator on the integers, it is the "inverse" of a
> multiplication operator. Inverse is a well-defined concept but not
> necessarily a function, it is a set theoretic mapping. E.G. m/n={ q:
> m=q*n} by definition, so that m/n which is actually a set which can
> be empty, a singleton, or infinite. In the case of m/n, it is then
> m/n = F^-1(m) where F(x)= n*x. Your reasoning would lead one to
> believe /: I x I -> I is a function, which it isn't.

Then why can you not perform 1/0 ? (or n/0)

Error: DIV BY ZERO




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

Date: Wed, 22 Dec 2004 09:31:53 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tpg6F3rcr9kU1@individual.net>

vonroach wrote:
> On Tue, 21 Dec 2004 10:39:22 -0500, "Richards Noah \(IFR LIT MET\)"
> <Noah.Richards@infineon.com> wrote:
>
>> You guys are arguing two different things.  The argument that 0/0 is
>> the set of all integers/reals/whatever you are using is the set
>> theory response to the question.  However, the more commonly used
>> form is the algebraicly accepted argument that states that division
>> is a function of the forms: Z / Z -> Q, R / R -> R, etc.  In this
>> definition, division by 0 is undefined for all Z or R, including 0.
>> So, you are both correct, but arguing different things.
>
>  Then infinity is undefined?

When divided by 0 it is.

n / 0 = undefined, it's always been as simple as this.

Try it on a calc for starters. You just can't divide by zero.




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

Date: Wed, 22 Dec 2004 09:35:24 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tpmqF3nehvpU1@individual.net>

David Kastrup wrote:
> Fred Bloggs <nospam@nospam.com> writes:
>
>> Alfred Z. Newmane wrote:
>>> Nicholas O. Lindan wrote:
>>>
>>>> "John Sefton" <john@petcom.com> wrote
>>>>
>>>>
>>>>> 0 can't be divided by itself,
>>>>
>>>> Sure it can: 0 / 0 = 0 * (1 / 0) = 0 * infinity = 1
>>>>
>>>> It works if the only three numbers in the universe are
>>>> 0, 1, and infinity -- A number system that seems very
>>>> suited to usenet.
>>> Except for the fact that: 0 / 0 = undefined
>>> Or actually more correct: n / 0 = undefined
>>>
>>
>> 0/0={ SET OF ALL INTEGERS }
>>
>> n/0= NULL SET  for n<>0
>>
>> It is very well-defined.
>
> So { SET OF ALL INTEGERS } = 0/0 = (0+0)/0 = (2*0)/0 = 2*(0/0)
>   = 2* {SET OF ALL INTEGERS } = {SET OF ALL EVEN INTEGERS}?
>
> Odd.

Thanks for pointing this out. n/0 = undefined. It's never been "SET OF
ALL INT'S"; though in basic math classses they do teach that it IS null
set, though the most correct and universal answer is simply n/0 =
undefined.




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

Date: Wed, 22 Dec 2004 09:45:20 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tq9fF3r82hgU1@individual.net>

vonroach wrote:
> On Wed, 22 Dec 2004 01:56:47 GMT, "Nicholas O. Lindan" <see@sig.com>
> wrote:
>
>> If I treat 0 as an imaginary number
>
> Now you say 0= -1^1/2?  You are using your imagination.

Sorry to nit pick, but in most any proper clac it should be written as
(-1)^(1/2), less you get -1 from -1^1/2, due to the '-' being evaluated
last. At least thats what happens in my TI86.




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

Date: Wed, 22 Dec 2004 09:48:57 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tqg7F3ru0j1U1@individual.net>

Tam/WB2TT wrote:
> <mmeron@cars3.uchicago.edu> wrote in message
> news:tURxd.14$35.4459@news.uchicago.edu...
>> In article <32p53dF3paevvU1@individual.net>, "Alfred Z. Newmane"
>> <a.newmane.remove@eastcoastcz.com> writes:
>>> Nicholas O. Lindan wrote:
>>>> "John Sefton" <john@petcom.com> wrote
>>>>
>>>>> 0 can't be divided by itself,
>>>>
>>>> Sure it can: 0 / 0 = 0 * (1 / 0) = 0 * infinity = 1
>>>>
>>>> It works if the only three numbers in the universe are
>>>> 0, 1, and infinity -- A number system that seems very
>>>> suited to usenet.
>>>
>>> Except for the fact that: 0 / 0 = undefined
>>>
>>> Or actually more correct: n / 0 = undefined
>>>
>> The two are not the same.
>>
>> The definition of the ratio a/b is
>>
>> a/b = r iff b*r = a
>>
>> for the case of n/0 there is no r such that r*0 = n (follows from the
>> definition of zero.  Therefore n/0 (for non zero n) *does not exist*.
>>
>> On the other hand, for 0/0, every r qualifies since for every r, r*0
>> = 0 (the definition of zero, again).  Therefore, 0/0 is truly
>> undefined, in the sense that it is impossible to *uniquely* assign a
>> value to the ratio r.
>>
>> Mati Meron                      | "When you argue with a fool,
>> meron@cars.uchicago.edu         |  chances are he is doing just the
>> same"
>
> It depends on how you get there,  [sin(x)]/x is certainly defined for
> all values of x including 0 and infinity.

Am I missing something here? you're still DIVIDING, so when x = 0, the
result is undefined.




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

Date: Wed, 22 Dec 2004 09:55:02 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tqrlF3qlbr8U1@individual.net>

vonroach wrote:
> On Mon, 20 Dec 2004 15:21:14 -0800, "Alfred Z. Newmane"
> <a.newmane.remove@eastcoastcz.com> wrote:
>
>> Except for the fact that: 0 / 0 = undefined
>>
>> Or actually more correct: n / 0 = undefined
>
> Really, Al Z?  Where did you get that doctorate in math? Various
> middle eastern types have worked hard to see that was not the case.

Did you have a refutal somewhere?




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

Date: Wed, 22 Dec 2004 12:01:43 -0600
From: John Fields <jfields@austininstruments.com>
Subject: Re: Is zero even or odd?
Message-Id: <qadjs0plb7g8j6gn1dcqk0l49jbpc63i52@4ax.com>

On Wed, 22 Dec 2004 13:56:07 GMT, vonroach <hadrainc@earthlink.net>
wrote:

>On Mon, 20 Dec 2004 15:24:39 +0100, Josef Moellers
><josef.moellers@fujitsu-siemens.com> wrote:
>
>>Gactimus wrote:
>>> I know 0 is neither negative or positive but what about odd/even? I think
>>> it's even. 
>>> 
>>> Odd numbers start at 1 and go every other number 1,3,5,7;1,-1,-3,-5,-7
>>> Even starts at 2 and go every other number 2,4,6,8;2,0,-2,-4,-6,-8
>>
>>As it can be divided by 2 without a remainder, it is obviously even.
>
>Er..., it can also be divided by every other number (rational,
>irrational, and imaginary) without a remainder, although some of us
>are amused by the strange concept of dividing nothing and the absurd
>idea that there may be a `remainder'. Then comes the wild assertion
>that when a number is divided by nothing, it becomes infinite.

---
???

For
 
             1
        x = ---
             n

x grows without bound as n approaches zero, no?

-- 
John Fields


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

Date: Wed, 22 Dec 2004 10:30:37 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Is zero even or odd?
Message-Id: <32tsuaF3sdifsU1@individual.net>

John Fields wrote:
> On Wed, 22 Dec 2004 13:56:07 GMT, vonroach <hadrainc@earthlink.net>
> wrote:
>
>> On Mon, 20 Dec 2004 15:24:39 +0100, Josef Moellers
>> <josef.moellers@fujitsu-siemens.com> wrote:
>>
>>> Gactimus wrote:
>>>> I know 0 is neither negative or positive but what about odd/even?
>>>> I think it's even.
>>>>
>>>> Odd numbers start at 1 and go every other number
>>>> 1,3,5,7;1,-1,-3,-5,-7 Even starts at 2 and go every other number
>>>> 2,4,6,8;2,0,-2,-4,-6,-8
>>>
>>> As it can be divided by 2 without a remainder, it is obviously even.
>>
>> Er..., it can also be divided by every other number (rational,
>> irrational, and imaginary) without a remainder, although some of us
>> are amused by the strange concept of dividing nothing and the absurd
>> idea that there may be a `remainder'. Then comes the wild assertion
>> that when a number is divided by nothing, it becomes infinite.
>
> ---
> ???
>
> For
>
>              1
>         x = ---
>              n
>
> x grows without bound as n approaches zero, no?

Exactly: graph y = 1 / x

You get a graph that loos like this:
(Both the  ---- line and the horizontal segments of ... are y = 0, drawn
as such since to show what the graph line looks like without being
overlapped by the origin (zero point) line.)


y = 1 / x:

                   | (doesn't quite reach 0,
                   |.  <--  since y = undefiend for x = 0)
                   |.
                   | ..
(<- etc) .......   |   ....... (etc ->)
         -------..-+----------
                  .|
             -->  .|
   (doesn't quite  |
      reach 0, since y = undefiend for x = 0)




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

Date: Wed, 22 Dec 2004 18:35:20 GMT
From: "Kevin Aylward" <salesEXTRACT@anasoft.co.uk>
Subject: Re: Is zero even or odd?
Message-Id: <I7jyd.2530$0W6.1555@fe2.news.blueyonder.co.uk>

David Kastrup wrote:
> "Kevin Aylward" <salesEXTRACT@anasoft.co.uk> writes:
>
>> vonroach wrote:
>>> On Mon, 20 Dec 2004 14:34:03 -0000, BB <BB@BB.BB> wrote:
>>>
>>>> The divisor would have to be something smaller than 0 like -2.
>>>> Therefore zero is both even and negative.
>>>
>>> Whoa!  A new concept: -0.  Let's make up some other numbers. I
>>> suggest wizzad and fugawe. I'd have suggested Arunda, but I believe
>>> some obscure African group already uses that in their alphabet.
>>
>> -0 often/usually signifies a limit approaching from the negative
>> direction.
>
> No.  One writes 0- for that.

Your quibbling here, smart arse.


Kevin Aylward
salesEXTRACT@anasoft.co.uk
http://www.anasoft.co.uk
SuperSpice, a very affordable Mixed-Mode
Windows Simulator with Schematic Capture,
Waveform Display, FFT's and Filter Design. 




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

Date: Wed, 22 Dec 2004 13:59:13 -0500
From: "robert j. kolker" <nowhere@nowhere.net>
Subject: Re: Is zero even or odd?
Message-Id: <32tug4F3nfo0lU2@individual.net>



Alfred Z. Newmane wrote:

> 
> Then why can you not perform 1/0 ? (or n/0)

If n/0 for n not 0 had a value then it would be equal to 0 and not equal 
to 0 at the same time. Contradictions are not permitted.

Bob Kolker


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

Date: Wed, 22 Dec 2004 18:18:00 GMT
From: Kim Helliwell <kimgh@pacbell.net>
Subject: Output pipes
Message-Id: <BDEEFA57.B78%kimgh@pacbell.net>

Is there a way to pipe output to a command without the command blocking?
By that I mean: I want to start several xgraph (an x-window graphing app)
sessions from a Perl script, and so far, each session blocks until I dismiss
the window. 

I tried:

open(GRAPH, "| xgraph &")

But that gives an error from xgraph that the data stream had errors.

I'm afraid I will have to invoke the whole fork/exec and IO redirection
machinery to do this, but I'd like to find a simpler way if anyone knows
one.

I have been reading the FAQ on system calls, and some of the questions come
close to helping, but not quite.

Any help appreciated. Email me (preferably) at kimgh@pacbell.net

Thanks,

Kim Helliwell



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

Date: Wed, 22 Dec 2004 10:59:06 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Output pipes
Message-Id: <221220041059068455%jgibson@mail.arc.nasa.gov>

In article <BDEEFA57.B78%kimgh@pacbell.net>, Kim Helliwell
<kimgh@pacbell.net> wrote:

> Is there a way to pipe output to a command without the command blocking?
> By that I mean: I want to start several xgraph (an x-window graphing app)
> sessions from a Perl script, and so far, each session blocks until I dismiss
> the window. 
> 
> I tried:
> 
> open(GRAPH, "| xgraph &")
> 
> But that gives an error from xgraph that the data stream had errors.

Have you tried it without the '&'? The open should fork a child
process, exec the xgraph program, which, if it accepts input from
stdin, block waiting for input. Meanwhile, your program will continue
to execute. Unfortunately, I don't have the xgraph program on my system
to test it.

> 
> I'm afraid I will have to invoke the whole fork/exec and IO redirection
> machinery to do this, but I'd like to find a simpler way if anyone knows
> one.

The fork and exec are already being done by the open,

> 
> I have been reading the FAQ on system calls, and some of the questions come
> close to helping, but not quite.
> 
> Any help appreciated. Email me (preferably) at kimgh@pacbell.net

Sorry, this is Usenet. I want my answer to appear on the millions of
monitors tuned into comp.lang.perl.misc. :)


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: 22 Dec 2004 08:32:12 -0800
From: "ajs@ajs.com" <AaronJSherman@gmail.com>
Subject: Regexp golf question
Message-Id: <1103733132.680108.143680@z14g2000cwz.googlegroups.com>

I wrote a program that generates passwords (
http://www.ajs.com/~ajs/mkpasswd.html for those who are curious ), and
was discussing it with someone who asked if it could restrict its
results to those that alternate sides of the keyboard. This is a
feature I've been mulling for a while, but I suggested to him that he
could just generate many passwords, and filter them using grep or perl
or whatever. The pattern I suggested was (I'll use Perl here):

m{ ^
(([12345qwertasdfgzxcvb][67890\-yuiophjkl;nm,./])*
|
([67890\-yuiophjkl;nm,./][12345qwertasdfgzxcvb])*)
$ }xi

But that feels wrong to me... it seems as if there should be some
shorter way to express that. Any regexp golfers want to take a swing?
Obviously I could have:

$left = qr{[12345qwertasdfgzxcvb]}i;
$right = qr{[67890\-yuiophjkl;nm,./]}i;
m{^(($left$right)*|($right$left)*)$};

but that's not quite the same as coming up with a shorter pattern.

Note that that's not ALL of the characters. I've left out a bunch of
punctuation for brevity, but you get the idea.

PS: I'm using the new Google Groups to try it out. If it eats my
formatting, above... well, sorry.



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

Date: 22 Dec 2004 18:10:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp golf question
Message-Id: <cqcdba$g21$1@mamenchi.zrz.TU-Berlin.DE>

ajs@ajs.com <AaronJSherman@gmail.com> wrote in comp.lang.perl.misc:
> I wrote a program that generates passwords (
> http://www.ajs.com/~ajs/mkpasswd.html for those who are curious ), and
> was discussing it with someone who asked if it could restrict its
> results to those that alternate sides of the keyboard. This is a
> feature I've been mulling for a while, but I suggested to him that he
> could just generate many passwords, and filter them using grep or perl
> or whatever. The pattern I suggested was (I'll use Perl here):

That doesn't seem to be an economical method to generate such
passwords.  The probability for a string to be alternating is
2**(length( $str) - 1).  (Any character can be first, every subsequent
character has a 50% chance of being wrong.)  So you'd generate about
128 passwords for an alternating one of length 8.  And it gets worse...

> m{ ^
> (([12345qwertasdfgzxcvb][67890\-yuiophjkl;nm,./])*
> |
> ([67890\-yuiophjkl;nm,./][12345qwertasdfgzxcvb])*)
> $ }xi
> 
> But that feels wrong to me... it seems as if there should be some
> shorter way to express that. Any regexp golfers want to take a swing?
> Obviously I could have:
> 
> $left = qr{[12345qwertasdfgzxcvb]}i;
> $right = qr{[67890\-yuiophjkl;nm,./]}i;
> m{^(($left$right)*|($right$left)*)$};
> but that's not quite the same as coming up with a shorter pattern.

I'd write that (using capturing parentheses for simplicity)

    /^$left?($right$left)*$right?$/i

It's not much shorter, but it doesn't build complete regexes for the
two possible cases, so I claim that logically it's only half as long.

Anno


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

Date: 22 Dec 2004 10:56:47 -0800
From: "ajs@ajs.com" <AaronJSherman@gmail.com>
Subject: Re: Regexp golf question
Message-Id: <1103741807.475480.41280@f14g2000cwb.googlegroups.com>


Anno Siegel wrote:

> > $left = qr{[12345qwertasdfgzxcvb]}i;
> > $right = qr{[67890\-yuiophjkl;nm,./]}i;
> > m{^(($left$right)*|($right$left)*)$};
>
> I'd write that (using capturing parentheses for simplicity)
>
>     /^$left?($right$left)*$right?$/i

Thanks, that's exactly what I was looking for. For some reason, I just
could not see that.



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

Date: Wed, 22 Dec 2004 12:42:27 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: retrieving Hash elements
Message-Id: <1103737335.46844@nntp.acecape.com>

Hello all,

Was trying to see if there is a way to retrieve hash keys in the order they
were created?  Which I have not found in any of my books or perldoc.  I
realize I could make an array for the keys, and call it back that way, but I
dunno, seems kind of kludge like.

Thought there might be a simple way, but everything I read says "..do not
have a guaranteed order."

Thanks ahead,

Daniel




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

Date: Wed, 22 Dec 2004 12:46:34 -0500
From: Ken <x3v0-usenet@yahoo.com>
Subject: Re: retrieving Hash elements
Message-Id: <_piyd.12025$FE.8903@fe37.usenetserver.com>

daniel kaplan wrote:
> Hello all,
> 
> Was trying to see if there is a way to retrieve hash keys in the order they
> were created?  Which I have not found in any of my books or perldoc.  I
> realize I could make an array for the keys, and call it back that way, but I
> dunno, seems kind of kludge like.
> 
> Thought there might be a simple way, but everything I read says "..do not
> have a guaranteed order."
> 
> Thanks ahead,
> 
> Daniel
> 
> 

This is actually a FAQ:
--------------------------------------------------------------------

4.60: How can I always keep my hash sorted?

     You can look into using the DB_File module and tie() using the 
$DB_BTREE
     hash bindings as documented in "In Memory Databases" in DB_File. The
     Tie::IxHash module from CPAN might also be instructive.



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



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

Date: Wed, 22 Dec 2004 17:55:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: retrieving Hash elements
Message-Id: <Wxiyd.1404$1U6.394@trnddc09>

daniel kaplan wrote:
> Was trying to see if there is a way to retrieve hash keys in the
> order they were created?  Which I have not found in any of my books
> or perldoc.  I realize I could make an array for the keys, and call
> it back that way, but I dunno, seems kind of kludge like.
>
> Thought there might be a simple way, but everything I read says "..do
> not have a guaranteed order."

Then why don't you believe it?
A hash is a mapping from scalar to scalar, just like e.g. the length 
function. Now, which order would you associate with the arguments of the 
length function?

Arrays on the other hand have natural numbers as domain, and because the 
human mind associates a natural order on natural numbers we also have an 
implicit order on the elements of an array.

In short: use the proper data structure. If order is important for you then 
use an array, not a hash.

jue




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

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


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