[33021] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4297 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 19 16:09:18 2014

Date: Sun, 19 Oct 2014 13:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 19 Oct 2014     Volume: 11 Number: 4297

Today's topics:
    Re: clever equal still experimental after so much time (Seymour J.)
    Re: clever equal still experimental after so much time <lionslair@consolidated.net>
    Re: fast math? (Was: prime) <xhoster@gmail.com>
        hash slice surprise <marc.girod@gmail.com>
    Re: hash slice surprise <hjp-usenet3@hjp.at>
    Re: hash slice surprise <marc.girod@gmail.com>
    Re: prime <bauhaus@futureapps.invalid>
    Re: prime <rweikusat@mobileactivedefense.com>
    Re: prime <hjp-usenet3@hjp.at>
    Re: prime <gamo@telecable.es>
    Re: prime <hjp-usenet3@hjp.at>
    Re: prime <lionslair@consolidated.net>
    Re: prime <bauhaus@futureapps.invalid>
    Re: prime <hjp-usenet3@hjp.at>
    Re: prime <gamo@telecable.es>
        what's wrong with given when? <marc.girod@gmail.com>
    Re: what's wrong with given when? <marc.girod@gmail.com>
    Re: what's wrong with given when? <marc.girod@gmail.com>
    Re: what's wrong with given when? <gamo@telecable.es>
    Re: what's wrong with given when? <rweikusat@mobileactivedefense.com>
    Re: what's wrong with given when? <rweikusat@mobileactivedefense.com>
    Re: what's wrong with given when? <rweikusat@mobileactivedefense.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 18 Oct 2014 22:31:45 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: clever equal still experimental after so much time
Message-Id: <544330a1$2$fuzhry+tra$mr2ice@news.patriot.net>

In <2Z2Xv.148824$_r4.12173@fx25.iad>, on 10/01/2014
   at 09:42 PM, Martin Eastburn <lionslair@consolidated.net> said:

>I had an 8080 that way and after working with it with my dad
>(distant) I  decided to write around it.
>I later got a new CPU in a new mainframe 

Mainframe? Not with an 8080.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Sat, 18 Oct 2014 22:07:01 -0500
From: Martin Eastburn <lionslair@consolidated.net>
Subject: Re: clever equal still experimental after so much time
Message-Id: <BVF0w.370978$JH1.110603@fx08.iad>

On 10/18/2014 10:31 PM, Shmuel (Seymour J.) Metz wrote:
> In <2Z2Xv.148824$_r4.12173@fx25.iad>, on 10/01/2014
>     at 09:42 PM, Martin Eastburn <lionslair@consolidated.net> said:
>
>> I had an 8080 that way and after working with it with my dad
>> (distant) I  decided to write around it.
>> I later got a new CPU in a new mainframe
>
> Mainframe? Not with an 8080.
>
Having had a PDP 8 and a Data General 1200 first and teaching in college
the machine code - not assembly and teaching boot IC code for the Air 
force designers the box that the computer is in is a frame.  The 
mainframe is the main cpu box and I had three other boxes attached and a
teletype and 132 column Daisey wheel printer from Xerox.

You naturally think in those days of the IBM 1600 (IIRC) maybe that was 
the printer and 1610 was the boat at the end of the CPU room.  Didn't 
have IT in those days.  Just computer geeks and key punch operators.

I was a charter member of the North Texas computer club and members were 
putting multiple cpu's in one frame and trying to do real computing. We 
used wheel printers, drum printers and drum disks. Anything we could 
scrounge.  The monster hurricane - Carla IIRC  provided us with many 
printers and computer stuff. Motels were flooded.

8" floppy - hard sector for more data storage than the 'new' 8" soft 
sector disks.  Have a pair of disk machines in the shop now.  Pertec drives.

Martin


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

Date: Fri, 17 Oct 2014 21:43:35 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: fast math? (Was: prime)
Message-Id: <m1sr62$4pi$1@dont-email.me>

On 10/16/14 12:28, G.B. wrote:
> On 16.10.14 19:52, gamo wrote:
>> View the numbers, there is no need to long long types, a unsigned long
>> (typically 64 bit number) is faster and could do the job.
> 
> Yes, native int, compiled on a 64 bit platform, easily outperforms
> a equivalent program written in Perl. More reason for me to ask:
> Is there a package in use with Perl that would speed up int
> computations in Perl?

I use Inline::C to do that.  It works like a charm.

Xho



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

Date: Sun, 19 Oct 2014 05:09:46 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: hash slice surprise
Message-Id: <b9ac1419-d452-47b0-8b51-1124a1858c5c@googlegroups.com>

Hello,

The following does not yield what I expected.
Can you help me understand my mistake?

$ perl -wle 'print q();
my %h;
$h{a}=q(a);
print scalar @h{qw(a b)};
my @q=@h{qw(a b)};
print scalar @q;
'
> > > > > > 
Use of uninitialized value in print at -e line 4.

2

I understand that $h{b} is undef.
But so is $q[1]
Why does it affect the value of the hash slice in scalar context?

Thanks,
Marc


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

Date: Sun, 19 Oct 2014 15:05:16 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: hash slice surprise
Message-Id: <slrnm47dod.6qp.hjp-usenet3@hrunkner.hjp.at>

On 2014-10-19 12:09, Marc Girod <marc.girod@gmail.com> wrote:
> The following does not yield what I expected.
> Can you help me understand my mistake?
>
> $ perl -wle 'print q();
> my %h;
> $h{a}=q(a);
> print scalar @h{qw(a b)};
> my @q=@h{qw(a b)};
> print scalar @q;
> '
>> > > > > > 
> Use of uninitialized value in print at -e line 4.
>
> 2
>
> I understand that $h{b} is undef.
> But so is $q[1]
> Why does it affect the value of the hash slice in scalar context?

Or in other words: What is the value of a hash slice in scalar context?

This little script may be instructive:

    #!/usr/bin/perl
    use warnings;
    use strict;
    my %a = (a => 1, b => 2, c => 3);

    my $x;
    $x = @a{'a', 'b'};
    print "x = $x\n";
    $x = @a{'a', 'c'};
    print "x = $x\n";
    $x = @a{'b', 'c'};
    print "x = $x\n";
    $x = @a{'b', 'd'};
    print "x = $x\n";
    __END__

    x = 2
    x = 3
    x = 3
    Use of uninitialized value $x in concatenation (.) or string at marc2
    line 14.
    x = 

It's obvious now, isn't it?

Or you could read perldoc perldata:

|      Slices in scalar context return the last item of the slice.
|
|          @a = qw/first second third/;
|          %h = (first => 'A', second => 'B');
|          $t = @a[0, 1];                  # $t is now 'second'
|          $u = @h{'first', 'second'};     # $u is now 'B'

        hp

-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sun, 19 Oct 2014 06:19:06 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: hash slice surprise
Message-Id: <d2e31695-3881-4061-9687-adf933645cbb@googlegroups.com>

Thanks Peter!

On Sunday, 19 October 2014 14:05:21 UTC+1, Peter J. Holzer  wrote:

> Or in other words: What is the value of a hash slice in scalar context?

Indeed.

> It's obvious now, isn't it?

Now that you show it.

> Or you could read perldoc perldata:
 ...
> |      Slices in scalar context return the last item of the slice.

Exactly what i missed.
Writing is easy, reading is hard.

Thanks again
Marc


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

Date: Fri, 17 Oct 2014 15:21:59 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: prime
Message-Id: <m1r564$8hs$1@dont-email.me>

On 17.10.14 14:09, Peter J. Holzer wrote:
> On 2014-10-17 11:44, G.B. <bauhaus@futureapps.invalid> wrote:
>> (4.16*10^17 * 44) / 2^64
>> .99226182825873365800
>>
>> (4.16*10^17 * 45) / 2^64
>> 1.01481323344643215023
>
> What do think you are computing here?

An approximation of 45 times as much as 4.16E17 that fits in
a machine int.



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

Date: Fri, 17 Oct 2014 15:12:42 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: prime
Message-Id: <8761fikco5.fsf@doppelsaurus.mobileactivedefense.com>

Kaz Kylheku <kaz@kylheku.com> writes:
> On 2014-10-16, hymie! <hymie@lactose.homelinux.net> wrote:
>> In our last episode, the evil Dr. Lacto had captured our hero,
>>   George Mpouras <gravitalsun@hotmail.foo>, who said:
>>>sub Find_the_prime_numbers_upto
>>>{
>>>		for (2 .. $number-1)
>>>		{	
>>>			if (0 == $number % $_)
>>>			{
>>>			$ok=0;
>>>			last
>>>			}
>>>		}
>>
>> I'm pretty sure that you can stop checking at int(sqrt(x)), rather than x-1 .
>>
>> I'm also pretty sure there's a proof, but I can't find it right now.
>
> Each factor f of a number x, such that f <= sqrt(x), pairs
> pairs with another number g, also a factor of x, such that
> f * g = x and g > sqrt(x).


[...]

I have to admit that I read this with interest but this is really so
bleeding obvious that it shouldn't need this many words. Let r be the
square root of x then

r * r = x

hence, for every two numbers s >= r, t > r: s * t > x. If no factors
smaller than r were found, there can't be any factors larger than r.



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

Date: Fri, 17 Oct 2014 19:45:59 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: prime
Message-Id: <slrnm42len.sml.hjp-usenet3@hrunkner.hjp.at>

On 2014-10-17 13:21, G.B. <bauhaus@futureapps.invalid> wrote:
> On 17.10.14 14:09, Peter J. Holzer wrote:
>> On 2014-10-17 11:44, G.B. <bauhaus@futureapps.invalid> wrote:
>>> (4.16*10^17 * 44) / 2^64
>>> .99226182825873365800
>>>
>>> (4.16*10^17 * 45) / 2^64
>>> 1.01481323344643215023
>>
>> What do think you are computing here?
>
> An approximation of 45 times as much as 4.16E17 that fits in
> a machine int.


That's obvious. But what does the number mean(*) and why do you compute it
and what does it have to do with your claim 'that computability in
plain C depends on "plural" typically meaning less than 45'?

(*) I know of course what it means (I did get my estimate of 4.16*10^17
    primes somewhere, you know), but that meaning doesn't fit into your
    claim at all. Indeed it reminds me of an anecdote (supposedly true,
    not a joke):

    A maths teacher gave his class the following test: "The school bus
    starts empty. At the first stop, it is boarded by 12 pupils. At the
    second stop, another 16 get on, and 7 get off, at the third stop 11
    get on the bus. We are now at the fourth and final stop. How old is
    the driver?" A majority of the pupils answered "32".


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Fri, 17 Oct 2014 20:23:34 +0200
From: gamo <gamo@telecable.es>
Subject: Re: prime
Message-Id: <m1rmr8$jfb$1@speranza.aioe.org>

El 17/10/14 a las 12:59, Peter J. Holzer escribió:
> Yeah, but only 1 GB, not "gigabytes" (plural). And in binary it's only
> 100E6 * 4 = 0.4 GB. So G.B. would have quibbled with that.

No problem, as I said is quick to generate. Here:

2142636916 oct 17 20:06 primes.200M

are the first 200 million primes. A file to play
with xz compressor.

Of course no problem regarding integer type, I think
the problem could rise before in the line

z = sqrt((double) i);

for lack of precision in

if (p[j] > z) break;

But this is hypothesizing the limits. Maybe RAM be first.

Cheers

-- 
http://www.telecable.es/personales/gamo/


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

Date: Fri, 17 Oct 2014 21:16:26 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: prime
Message-Id: <slrnm42qoa.e5m.hjp-usenet3@hrunkner.hjp.at>

On 2014-10-17 18:23, gamo <gamo@telecable.es> wrote:
> El 17/10/14 a las 12:59, Peter J. Holzer escribió:
>> Yeah, but only 1 GB, not "gigabytes" (plural). And in binary it's only
>> 100E6 * 4 = 0.4 GB. So G.B. would have quibbled with that.
>
> No problem, as I said is quick to generate. Here:
>
> 2142636916 oct 17 20:06 primes.200M
>
> are the first 200 million primes. A file to play
> with xz compressor.


Sigh.

        hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Fri, 17 Oct 2014 21:18:12 -0500
From: Martin Eastburn <lionslair@consolidated.net>
Subject: Re: prime
Message-Id: <P5k0w.500173$O13.113746@fx17.iad>

On 10/17/2014 4:03 AM, gamo wrote:
> El 17/10/14 a las 06:13, Martin Eastburn escribió:
>> I did factorial 1000 in three seconds with my i7
>> â—¦CPU_Name: Intel(R) Core(TM) i7-4960X CPU @ 3.60GHz
>> 32 GB of memory.
>
> You must be refering to factorial of 10000 or higher.
>
In Perl - yes I was.  1000 was to easy to seem to be a test.

Martin


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

Date: Sat, 18 Oct 2014 14:28:28 +0200
From: Georg Bauhaus <bauhaus@futureapps.invalid>
Subject: Re: prime
Message-Id: <m1tmdc$p63$1@dont-email.me>

On 17.10.14 19:45, Peter J. Holzer wrote:
>      A maths teacher gave his class the following test: "The school bus
>      starts empty. At the first stop, it is boarded by 12 pupils. At the
>      second stop, another 16 get on, and 7 get off, at the third stop 11
>      get on the bus. We are now at the fourth and final stop. How old is
>      the driver?" A majority of the pupils answered "32".

The number 45 is less disconnected:

- if phrases "gigabytes of primes" etc are understood to be about measuring
   the number of primes, not the size of any one prime, this understanding
   means that the algorithm needs to count primes as well as compute them;

- computing this result using machine ints implies---here is the
   indirection---that we can only count up to a number of primes,
   no matter how these are computed.

Silly and trivial as it will seem, the 45 connects thus to an estimate of
possible meanings of the plural of prime number whenever 64 bit uints store
the plural: higher counts do not exist. This alone will limit what can be
computed in plain C, or else one needs some other coding of higher numbers.
(Or, one doesn't need, actually, insofar as computing enough prime does
not require it in the first place, "enough" meaning that the plural be
way below 45 times what's in the first 2^64.)

Now, there is likely more fun in school buses.



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

Date: Sat, 18 Oct 2014 18:14:24 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: prime
Message-Id: <slrnm454f0.jlk.hjp-usenet3@hrunkner.hjp.at>

On 2014-10-18 12:28, Georg Bauhaus <bauhaus@futureapps.invalid> wrote:
> On 17.10.14 19:45, Peter J. Holzer wrote:
>>      A maths teacher gave his class the following test: "The school bus
>>      starts empty. At the first stop, it is boarded by 12 pupils. At the
>>      second stop, another 16 get on, and 7 get off, at the third stop 11
>>      get on the bus. We are now at the fourth and final stop. How old is
>>      the driver?" A majority of the pupils answered "32".
>
> The number 45 is less disconnected:

At least it is a number which can be used while computing the solution
to the problem. But your use of it was so wrong that it betrayed a lack
of understanding only marginally less bad than that of the pupils.


> - if phrases "gigabytes of primes" etc are understood to be about measuring
>    the number of primes, not the size of any one prime,

Neither. "Gigabytes of primes" can only refer to the combined size of
the primes. "byte" is a unit of size. 

Just like "tons of apples" doesn't refer to the number of apples or the
the weight of an individual apple but to the combined weight of a large
number of them.


>    this understanding means that the algorithm needs to count primes
>    as well as compute them;

Actually, it doesn't. It just has to store them. Then you can measure
the size of the output directly. (Actually, I'd say that an algorithm
which doesn't actually output the primes but only counts them doesn't
produce "gigabytes of primes" - it just produces a single number, which
is most likely neither gigabytes long nor a prime).


> - computing this result using machine ints implies---here is the
>    indirection---that we can only count up to a number of primes,
>    no matter how these are computed.

The largest prime we can compute using 64 bit numbers will be close to
2**64.


> Silly and trivial as it will seem, the 45 connects thus to an estimate of
> possible meanings of the plural of prime number whenever 64 bit uints store
> the plural: higher counts do not exist.

Right, but it's the other way around. About every 45th integer in
[0..2**64] is a prime. So the maximum[1] number of primes we can find
with 64 bit numbers is 1/45 of 2**64, not 45 times something.


> This alone will limit what can be computed in plain C, or else one
> needs some other coding of higher numbers.  (Or, one doesn't need,
> actually, insofar as computing enough prime does not require it in the
> first place, "enough" meaning that the plural be way below 45 times
> what's in the first 2^64.)

We weren't talking about multiples of 2**64, we were talking about
multiples of "gigabyte". The term "gigabyte" has a well-defined
meaning[2], you can't just play Humpty Dumpty with it[3]. And no matter
how you turn it, there are a lot more than 45 gigabytes of primes you
can compute with 64 bit numbers.

So you put that factor of 45 into the enumerator instead of the
denominator and you mixed up 2**64 with "gigabyte" (what's a factor of
18 billion and the wrong unit between friends?).

        hp


[1] Actually, the maximum is somewhat higher, since the N/ln(N) is 
    asymptotic to the true number from below.
[2] Or four of them, if you combine the two meanings of "giga" with the
    two meanings of "byte". 
[3] Well, you can. But don't expect anybody to play along.

-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sat, 18 Oct 2014 22:12:49 +0200
From: gamo <gamo@telecable.es>
Subject: Re: prime
Message-Id: <m1uhk4$5r3$1@speranza.aioe.org>

El 18/10/14 a las 18:14, Peter J. Holzer escribió:
> Just like "tons of apples" doesn't refer to the number of apples or the
> the weight of an individual apple but to the combined weight of a large
> number of them.

Just in that sense I wrote gigabytes. When a commodity is cheap it's
measured by weight, in Tons.

Well, it must be a big discussion if a certain prime, key of a 
cryptographic message, is cheap or not. Certainly not, but
for "unsigned long int" types, It must be.

As the wikipedia says, "As of April 2014, the largest known prime number 
has 17,425,170 decimal digits."

-- 
http://www.telecable.es/personales/gamo/


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

Date: Sun, 19 Oct 2014 06:52:03 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: what's wrong with given when?
Message-Id: <165270ed-fab1-4a66-8100-0757d6a97c46@googlegroups.com>

Hi,

In another thread, I read about experimental features.
In the case of given...when, am I correct that it was for long *not* experimental, then became 'experimental' fairly recently (in 5.18 or so).

I take it that it did not become 'deprecated'.
So, what's the problem with it?

Marc


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

Date: Sun, 19 Oct 2014 06:59:31 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: what's wrong with given when?
Message-Id: <7afccef1-efdd-4f90-8c06-27140d2025cf@googlegroups.com>

On Sunday, 19 October 2014 14:52:06 UTC+1, Marc Girod  wrote:

> So, what's the problem with it?

Sorry, my asking the question led me to look for the answer.
And probably to find it in perlsyn.

- redundant with for
- buggy between 5.10 and 5.16

Marc


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

Date: Sun, 19 Oct 2014 07:09:50 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: what's wrong with given when?
Message-Id: <4f421f4a-0e39-4649-bc1a-51f18eb677d8@googlegroups.com>

On Sunday, 19 October 2014 14:59:34 UTC+1, Marc Girod  wrote:

> And probably to find it in perlsyn.

Almost.
Exit 'given'.
What about 'when'?
The example with for..when in perlsyn also warns about when being experimental with perl 5.18...

$ perl -M5.018 -wle 'my$a=1;for($a){when(1){print"yes"}}'
when is experimental at -e line 1.
yes

Marc


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

Date: Sun, 19 Oct 2014 17:28:59 +0200
From: gamo <gamo@telecable.es>
Subject: Re: what's wrong with given when?
Message-Id: <m20lc0$jkq$1@speranza.aioe.org>

El 19/10/14 a las 16:09, Marc Girod escribió:
> On Sunday, 19 October 2014 14:59:34 UTC+1, Marc Girod  wrote:
>
>> And probably to find it in perlsyn.
>
> Almost.
> Exit 'given'.
> What about 'when'?
> The example with for..when in perlsyn also warns about when being experimental with perl 5.18...
>
> $ perl -M5.018 -wle 'my$a=1;for($a){when(1){print"yes"}}'
> when is experimental at -e line 1.
> yes
>
> Marc
>

This synopsis

            use feature qw(say switch);
            given ($foo) {
                when (1)          { say "\$foo == 1" }
                when ([2,3])      { say "\$foo == 2 || \$foo == 3" }
                when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
                when ($_ > 100)   { say "\$foo > 100" }
                default           { say "None of the above" }
            }

I think explains than "when" it's an enhanced "if"
and therefore no stress tested.

-- 
http://www.telecable.es/personales/gamo/


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

Date: Sun, 19 Oct 2014 19:38:26 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: what's wrong with given when?
Message-Id: <87r3y3kiql.fsf@doppelsaurus.mobileactivedefense.com>

Marc Girod <marc.girod@gmail.com> writes:
> On Sunday, 19 October 2014 14:52:06 UTC+1, Marc Girod  wrote:
>
>> So, what's the problem with it?
>
> Sorry, my asking the question led me to look for the answer.
> And probably to find it in perlsyn.
>
> - redundant with for

If you look at the section immediately above 'Switch Statements', you'll
notice that using a for(each) pseudo-loop in this way is described with
the words

	Such constructs are quite frequently used [...] because older
	versions of Perl had no official switch statement

Emulating multi-way conditionals in this way he surely been documented
ever since the first perl version I used (IIRC, 5.004_03), meaning,
given and for already had signficant overlaps in their functionality by
the time the former was introduced.
        
> - buggy between 5.10 and 5.16

For a certain definition of 'buggy'. I didn't notice this in practice so
far.


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

Date: Sun, 19 Oct 2014 20:38:09 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: what's wrong with given when?
Message-Id: <87mw8rkfz2.fsf@doppelsaurus.mobileactivedefense.com>

Marc Girod <marc.girod@gmail.com> writes:
> In another thread, I read about experimental features.
> In the case of given...when, am I correct that it was for long *not*
> experimental, then became 'experimental' fairly recently (in 5.18 or
> so).
>
> I take it that it did not become 'deprecated'.
> So, what's the problem with it?

This depends on whom you ask. In my opinion, 'smart matching' is a
stupid idea: It comes down to making the same operator to upteemth
different, non-obvious things when applied to different kinds of
arguments which - in theory - all have to be memoized so that 'dumb'
humans don't accidentally outsmart themselves when using 'smart'
operators. On top of that comes another table of 'smart matching
exception', ie, smartly avoiding the not-smart-enough smart operator
where it's behaviour doesn't make much sense. This should all go the way
of the Dodo and be replaced with something much simpler.

The other argument does against the idea of supporting multi-way
conditionals in general: There's nothing which can be expressed with one
which cannot also be expressed with a sequence of independent or
semi-dependent tests a la

if (...) {
} elsif (...) {
} elsif (...) {
} else {
}

and since that's "what all good people have always used", multiway
conditionals are outlandish nonsense no "good people" would ever use
(or would want others to use since they'd need to learn to understand
them then).



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

Date: Sun, 19 Oct 2014 20:42:39 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: what's wrong with given when?
Message-Id: <87iojfkfrk.fsf@doppelsaurus.mobileactivedefense.com>

gamo <gamo@telecable.es> writes:
> El 19/10/14 a las 16:09, Marc Girod escribió:
>> On Sunday, 19 October 2014 14:59:34 UTC+1, Marc Girod  wrote:
>>
>>> And probably to find it in perlsyn.
>>
>> Almost.
>> Exit 'given'.
>> What about 'when'?
>> The example with for..when in perlsyn also warns about when being experimental with perl 5.18...
>>
>> $ perl -M5.018 -wle 'my$a=1;for($a){when(1){print"yes"}}'
>> when is experimental at -e line 1.
>> yes
>>
>> Marc
>>
>
> This synopsis
>
>            use feature qw(say switch);
>            given ($foo) {
>                when (1)          { say "\$foo == 1" }
>                when ([2,3])      { say "\$foo == 2 || \$foo == 3" }
>                when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
>                when ($_ > 100)   { say "\$foo > 100" }
>                default           { say "None of the above" }
>            }
> I think explains than "when" it's an enhanced "if"
> and therefore no stress tested.

That's a non-sequitur. Among other things, I'm using given/when in code
which manages 'firewall rules source address lists' and makes real-time
content-filtering decisions for thousands of mobile VPN users
(in three continents) and it works very nicely 'under stress'.


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 4297
***************************************


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