[32875] in Perl-Users-Digest
Perl-Users Digest, Issue: 4153 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 25 14:14:28 2014
Date: Tue, 25 Feb 2014 11:14:07 -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 Tue, 25 Feb 2014 Volume: 11 Number: 4153
Today's topics:
Re: use strict; use warnings; <rweikusat@mobileactivedefense.com>
Re: use strict; use warnings; <news@todbe.com>
Re: use strict; use warnings; <news@todbe.com>
Re: use strict; use warnings; <news@lawshouse.org>
Re: use strict; use warnings; <justin.1401@purestblue.com>
Re: use strict; use warnings; <justin.1401@purestblue.com>
Re: use strict; use warnings; <jurgenex@hotmail.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Feb 2014 11:55:42 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: use strict; use warnings;
Message-Id: <877g8jo18h.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
>> Marius Gavrilescu <marius@ieval.ro> writes:
>> > Marek Novotny <mach2@hushmail.com> writes:
>> >
>> >> When I started to try to use the use strict and warnings, I got warnings
>> >> such as: Scalar value @diamonds[$i] better written as $diamonds[$i] at ./
>> >> obj10.pl line 55.
>> >>
>> >> But the whole point of what I am doing is loading elements into an
>> >> array... So I wanted it as @diamonds, not $diamonds, and so on.
>> >
>> > In Perl, the tenth element of array @something is $something[10].
>>
>> That would be the eleventh element. The tenth is $something[9].
>
> It's not uncommon, when talking about languages like Perl which index
> from 0, to start the ordinals at 'zeroth'.
I've never heard or seen anyone do this and not even the Perl
documentation does,
shift Shifts the first value of the array off and returns it,
first BLOCK LIST
Similar to "grep" in that it evaluates BLOCK setting $_ to
each element of LIST in turn. "first" returns the first
element where the result from BLOCK is a true value. If BLOCK
never returns true or LIST was empty then "undef" is
returned.
$[ The index of the first element in an array,
The tenth element is the one which as nine other elements in front of it
and what set of indices is used for random access to these elements is a
completely unrelated question. This results in a sensible convention
(nth element as n - 1 elements in front of it) while the other idea
doesn't ('-1 elements in front of it' makes no sense).
It should also be noted that 'indexing from 0' is a property Perl very
likely inherited from C (encouraged by all the other languages which
also did this) but that it hangs somewhat in the air because it didn't
inherit pointer arithmetic: In C, a[0] is the element whose distance
from the start of the array is 0, other ways to express the same would
be *a or *(a + 0). Since the 2nd element has one element in front of it,
its distance from the start of the arrays is 1 and so on.
------------------------------
Date: Tue, 25 Feb 2014 04:00:01 -0800
From: "$Bill" <news@todbe.com>
Subject: Re: use strict; use warnings;
Message-Id: <lei0k1$drl$2@dont-email.me>
On 2/24/2014 15:47, Ben Morrow wrote:
>
> Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
>> Marius Gavrilescu <marius@ieval.ro> writes:
>>>
>>> In Perl, the tenth element of array @something is $something[10].
>>
>> That would be the eleventh element. The tenth is $something[9].
>
> It's not uncommon, when talking about languages like Perl which index
> from 0, to start the ordinals at 'zeroth'.
Except the zeroth and first element are the same thing. :)
------------------------------
Date: Tue, 25 Feb 2014 04:10:17 -0800
From: "$Bill" <news@todbe.com>
Subject: Re: use strict; use warnings;
Message-Id: <lei17b$jfs$1@dont-email.me>
On 2/24/2014 15:55, Ben Morrow wrote:
>
> Personally I use qw() when the construction will extend over several
> lines; it makes the close-quote look better. I also tend to use q{} for
> (and only for) quoting Perl, because, as you say, a {} block looks like
> it should have code inside.
I always use qw(...) over qw/.../ it is a list after all and don't see
what /.../ gets you that would equate to a list/array.
There are only maybe 10 examples in the entire Perl man pages that use
qw// vs qw() which has hundreds of examples.
------------------------------
Date: Tue, 25 Feb 2014 13:02:12 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: use strict; use warnings;
Message-Id: <ReSdnaHr8-nJCZHOnZ2dnUVZ8nSdnZ2d@giganews.com>
On 25/02/14 12:00, $Bill wrote:
> Except the zeroth and first element are the same thing
What fun. Does that mean we have, for the first time in history, a need
for the cardinal "oneth"? The first element is the zeroth; the second
is the oneth.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 25 Feb 2014 14:54:01 +0000
From: Justin C <justin.1401@purestblue.com>
Subject: Re: use strict; use warnings;
Message-Id: <9dnuta-b27.ln1@zem.masonsmusic.co.uk>
On 2014-02-24, Peter J. Holzer <hjp-usenet3@hjp.at> wrote:
> On 2014-02-24 12:00, Marius Gavrilescu <marius@ieval.ro> wrote:
>> In Perl, the tenth element of array @something is $something[10]. So the
>> warnings are correct — you should write $diamonds[$i] instead of
>> @diamonds[$i].
>
> Yes. It is tempting to think of the sigil as denoting the type of the
> variable ($ for scalars, @ for arrays, % for hashes), but it's wrong.
> The sigil denotes the type of the value: A single element of an array is
> a scalar, so it needs a $. several elements form a list, so we use an @.
> You could write @diamonds[$i, $j].
Yup, ignore what I said, what peter said is way better.
> When compared to natural languages, the sigils are similar to articles
> or numerals. "$" means "a" and "@" and "%" mean "some" (so Perl has two
> kinds of plural).
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 25 Feb 2014 14:40:10 +0000
From: Justin C <justin.1401@purestblue.com>
Subject: Re: use strict; use warnings;
Message-Id: <ajmuta-b27.ln1@zem.masonsmusic.co.uk>
On 2014-02-24, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Later on you will meet globs, which have a * sigil; again, this is not
> related in any way to the use of * to mean multiplication.
I think I've only ever used globs when doing the exercises in
Learning Perl.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 25 Feb 2014 08:07:56 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <trfpg99mpnqilk0abj0hfjeeba7bgepi4n@4ax.com>
Ben Morrow <ben@morrow.me.uk> wrote:
>It's not uncommon, when talking about languages like Perl which index
>from 0, to start the ordinals at 'zeroth'.
Only by those people, who also celebrated the start of the third
millenium at the end of 1999.
jue
------------------------------
Date: Tue, 25 Feb 2014 11:17:43 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <I6SdnXwEFt6qTZHOnZ2dnUVZ_r2dnZ2d@supernews.com>
On Tue, 25 Feb 2014 00:38:08 +0000, Jens Thoms Toerring wrote:
>> my $i = 0; my @randomdeck;
>> while ($i < 51){
>> $randomdeck[$i] = shift(@startingdeck); $i++;
>> $randomdeck[$i] = pop(@startingdeck); $i++;
>> }
>
> You don't necessarily need that '$i' variable and you can also use push
> here (as required):
>
> while ( @startingdeck ) {
> push @randomdeck, shift @startingdeck;
> push @randomdeck, pop @startingdeck;
> }
I like this bit of code! Very nice!
> But the whole exercise looks rather strange: at first they write
> something about 'sufficiently "shuffles"' and a bit later you have "but
> not a randomly shuffled". That makes no sense to me - I've never seem a
> definition of "sufficiently but not randomly shuffled" - for me
> "shuffled" implies some elememt of at least pseudo-randomness...
>
> What you do, i.e. taking the card from the top and then the one from the
> bottom, and repeating the exact same pro- cedure until the deck is
> empty, might fit the bill but there's no way to know for certain.
Well I think they really just want to see us using pop, push and shift to
ensure we understand it at least in the terms it is presented at this
particular level. Certainly I've shown that so... Perhaps a free pass at
this point.
> Perhaps the most you can learn from this isn't something specific to
> Perl but that very often the requirements you get for a programming task
> are badly inconsistent (or some- times even violate the principle of
> causality;-). So now you can start on the second, hard part of the
> task: discuss with the customer what the requirements actually are
> supposed to mean without pissing him off by making him feel stupid;-)
>
> Regards, Jens
That's certainly the truth. I think more and more I'd like to show sample
code and get feed back from the teacher before submitting a whole
solution. I am glad for the errors. It raised a lot of good points and
provided much food for thought.
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
Date: Tue, 25 Feb 2014 11:19:08 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <I6SdnX8EFt4RTZHOnZ2dnUVZ_r2dnZ2d@supernews.com>
On Tue, 25 Feb 2014 01:04:21 +0000, Ben Morrow wrote:
> Quoth Marek Novotny <mach2@hushmail.com>:
>> On Mon, 24 Feb 2014 10:49:21 +0000, Ben Morrow wrote:
>>
>> > Have you learned about 'reverse' yet? If not:
>>
>> Yes, they did show a fairly okay example of reverse. We had to take
>> /etc/
>> passwd and reverse all of the fields. We used split as well.
>
> There's a subtlety here waiting to trip you up: like many of Perl's
> builtins, 'reverse' actually does two different things, depending on the
> 'context' it's called in. It looks like you were using reverse in scalar
> context, which takes a string ("abc") and reverses it ("cba"). I was
> referring to reverse in list context, which takes a list ("ab", "cd")
> and reverses that ("cd", "ab").
>
> Since you've got a perfectly good collection of introductory Perl books,
> written by people who know more about teaching Perl than me, I'm not
> going to try to explain 'context' any more than that; but I am going to
> recommend that when you get to that chapter in the book you read it
> carefully. Context is one of the features of Perl that's not common in
> other languages, so beginners are often confused by it.
>
> Ben
Just started highlighting examples of reverse and in two different
contexts from the Learning Perl book. You're right on time, sir!!
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
Date: Tue, 25 Feb 2014 11:20:42 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <I6SdnX4EFt53TZHOnZ2dnUVZ_r2dnZ2d@supernews.com>
On Tue, 25 Feb 2014 07:12:37 +0000, Henry Law wrote:
> On 24/02/14 17:32, Marek Novotny wrote:
>> I actually think they are using the wrong word in their description.
>
> I actually think you are smarter than your instructors, even though they
> know more than you do at present.
Henry, what a nice thing to say. I hope my next teacher is 10x smarter
than me, honest.
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
Date: Tue, 25 Feb 2014 11:24:35 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <I6SdnXkEFt5OTJHOnZ2dnUVZ_r2dnZ2d@supernews.com>
On Tue, 25 Feb 2014 14:54:01 +0000, Justin C wrote:
> On 2014-02-24, Peter J. Holzer <hjp-usenet3@hjp.at> wrote:
>> On 2014-02-24 12:00, Marius Gavrilescu <marius@ieval.ro> wrote:
>>> In Perl, the tenth element of array @something is $something[10]. So
>>> the warnings are correct — you should write $diamonds[$i] instead of
>>> @diamonds[$i].
>>
>> Yes. It is tempting to think of the sigil as denoting the type of the
>> variable ($ for scalars, @ for arrays, % for hashes), but it's wrong.
>> The sigil denotes the type of the value: A single element of an array
>> is a scalar, so it needs a $. several elements form a list, so we use
>> an @.
>> You could write @diamonds[$i, $j].
>
> Yup, ignore what I said, what peter said is way better.
>
>
>> When compared to natural languages, the sigils are similar to articles
>> or numerals. "$" means "a" and "@" and "%" mean "some" (so Perl has two
>> kinds of plural).
>
>
> Justin.
Good stuff and this is precisely part of what I am reading now but how it
is stated here makes 10x more sense! Thanks!
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
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 4153
***************************************