[31532] in Perl-Users-Digest
Perl-Users Digest, Issue: 2791 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 27 00:09:44 2010
Date: Tue, 26 Jan 2010 21:09:25 -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, 26 Jan 2010 Volume: 11 Number: 2791
Today's topics:
Re: print array with separator? <rvtol+usenet@xs4all.nl>
Re: print array with separator? <john@castleamber.com>
Re: print array with separator? <jurgenex@hotmail.com>
Re: print array with separator? <tadmc@seesig.invalid>
Re: print array with separator? <ben@morrow.me.uk>
Re: print array with separator? <john@castleamber.com>
Re: print array with separator? <uri@StemSystems.com>
Re: print array with separator? <rvtol+usenet@xs4all.nl>
Re: print array with separator? <sreservoir@gmail.com>
Re: print array with separator? <ben@morrow.me.uk>
Re: strip all but second second line from bottom and th <derykus@gmail.com>
strip all but second second line from bottom and then s <kjl@aol.com>" <bbeasley@beasleyhull.com>
Re: strip all but second second line from bottom and th <jurgenex@hotmail.com>
Re: strip all but second second line from bottom and th sln@netherlands.com
Re: When to use "use strict;"? <tadmc@seesig.invalid>
Re: When to use "use strict;"? <sreservoir@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 Jan 2010 20:28:28 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: print array with separator?
Message-Id: <4b5f425c$0$22940$e4fe514c@news.xs4all.nl>
John Bokma wrote:
> the arguments
> against using map in void context are more a matter of taste IMO. The
> "its not intended for that" is weak at best, in my (current) opinion.
Recent perls do pretty well with map in a void context.
Unrecent perls have real issues with a map inside a map:
memory allocated by the inner map gets released too late.
Nothing to much worry about, unless the inner map is big.
--
Ruud
------------------------------
Date: Tue, 26 Jan 2010 14:13:33 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: print array with separator?
Message-Id: <87r5pc1v6a.fsf@castleamber.com>
"Dr.Ruud" <rvtol+usenet@xs4all.nl> writes:
> John Bokma wrote:
>
>> the arguments
>> against using map in void context are more a matter of taste IMO. The
>> "its not intended for that" is weak at best, in my (current) opinion.
>
> Recent perls do pretty well with map in a void context.
which gives me the impression that it's more a matter of taste/style
than using map "wrong" of for something it is not intented for.
But before the flame war really starts, let me repeat that I don't like
it, and it will be unlikely to show up in my code in the near future.
I've done TE for a book in which the author used a lot map in void
context, and each time I remarked "Don't use void in a map
context". While I don't think it's wrong, I wouldn't recommend it to
use it that often in a book. I haven't seen the final version of the
book yet, so no idea what happened with my advice. But it also made me
think: what's really wrong with it. And I couldn't think of a strong
argument other than that it looks odd (to me). And some of the code
looked better (IMO, again style) with for.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Tue, 26 Jan 2010 12:39:33 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: print array with separator?
Message-Id: <81eul55hsac94i83sju2shns6soejkagf9@4ax.com>
John Bokma <john@castleamber.com> wrote:
>"Uri Guttman" <uri@StemSystems.com> writes:
>> but in conveying
>> meaning to the reader. map is intended to generate a list, not execute
>> side effects.
>
>But who decides that map is not intended for its side effects? In Perl
>there are IMO quite some constructs that are used in somewhat unexpected
>ways, especially to people new to the language.
The root cause of this confusion is probably that for most people with a
formal background in computer science 'map()' is the first operation
that comes to mind when you want to apply an operation to a list of
values. After all it is one of the three canonical higher-order list
functions map, reduce, and filter.
And because Perl happens to have a function map() that happens to work
the same way in a functional as well as in an imperative programming
style it is only natural that people are using it for both purposes.
And I don't see anything wrong with that.
jue
------------------------------
Date: Tue, 26 Jan 2010 16:29:12 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: print array with separator?
Message-Id: <slrnhluqv7.2n2.tadmc@tadbox.sbcglobal.net>
John Bokma <john@castleamber.com> wrote:
> "Uri Guttman" <uri@StemSystems.com> writes:
>
>>>>>>> "JB" == John Bokma <john@castleamber.com> writes:
>>
>> JB> I wouldn't use it though, but like Abigail, IIRC, once wrote, there is
>> JB> no reason to have a problem with map in void context because we use
>> JB> other functions in void context without problems (like print).
>>
>> the point with map in void context is not efficiency
>
> It used to be, and back then, IMO there was a much stronger argument to
> not use map in void context.
>
>> but in conveying
^^^^^^^^^
>> meaning to the reader. map is intended to generate a list, not execute
^^^^^^^^^^^^^^^^^^^^^
>> side effects.
>
> But who decides that map is not intended for its side effects?
That is a red herring.
What is intended by map does not matter, what map conveys to the reader
is what matters.
map conveys "I am building a list" (because it returns a list).
>> for modifier does the same thing and is meant for side
>> effects as it doesn't generate a list. perl has many related things like
>> this and you should choose the one with better semantics for your
>> intentions. map generates lists so use it that way. for modifier doesn't
>> generate lists so use it for side effects.
>
> Like I wrote, I don't like it, and won't use it. But the arguments
> against using map in void context are more a matter of taste IMO.
Using map in a void context is an obfuscation.
Arguments against obfuscation are NOT a matter of taste, they are
a matter of Good Programming Practice.
> The
> "its not intended for that" is weak at best, in my (current) opinion.
That was not Uri's argument.
Uri's argument was that map in void context conveys the wrong meaning.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Tue, 26 Jan 2010 22:54:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: print array with separator?
Message-Id: <8e8437-hdk.ln1@osiris.mauzo.dyndns.org>
Quoth Tad McClellan <tadmc@seesig.invalid>:
> John Bokma <john@castleamber.com> wrote:
> > "Uri Guttman" <uri@StemSystems.com> writes:
> >
> >>>>>>> "JB" == John Bokma <john@castleamber.com> writes:
> >>
> >> JB> I wouldn't use it though, but like Abigail, IIRC, once wrote, there is
> >> JB> no reason to have a problem with map in void context because we use
> >> JB> other functions in void context without problems (like print).
> >>
> >> the point with map in void context is not efficiency
> >
> > It used to be, and back then, IMO there was a much stronger argument to
> > not use map in void context.
> >
> >> but in conveying
> ^^^^^^^^^
> >> meaning to the reader. map is intended to generate a list, not execute
> ^^^^^^^^^^^^^^^^^^^^^
> >> side effects.
> >
> > But who decides that map is not intended for its side effects?
>
>
> That is a red herring.
>
> What is intended by map does not matter, what map conveys to the reader
> is what matters.
>
> map conveys "I am building a list" (because it returns a list).
So does delete. Would you object to delete in void context?
Ben
------------------------------
Date: Tue, 26 Jan 2010 17:08:44 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: print array with separator?
Message-Id: <87hbq81n2b.fsf@castleamber.com>
Tad McClellan <tadmc@seesig.invalid> writes:
> Arguments against obfuscation are NOT a matter of taste, they are
> a matter of Good Programming Practice.
Like I already wrote several times: I wouldn't use map in void context
at this stage. But I don't think one /must/ (or /should/) not use it in
void context.
> Uri's argument was that map in void context conveys the wrong meaning.
One could - to some extent - argue the same for using a 'for' for its
aliasing effect in my opinion, e.g.
my $string = 'hello, world';
for ( $string ) {
s/e/a/;
s/l/1/;
}
I consider the above a Perl idiom; one that I have no problem using.
Yet I am sure it would confuse quite some beginning Perl programmers. To
them it might convey a wrong meaning.
But I don't like to dumb down my Perl code to a beginner's level. YMMV,
in my opinion, it's opinion.
And to avoid of being accused of "promoting map in void context", let me
repeat again: I don't use map in void context, and when TEing a
technical book I recommended the author not to use map in void
context. But it's (no longer) a religious issue to me.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Tue, 26 Jan 2010 18:11:29 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: print array with separator?
Message-Id: <87bpggh36m.fsf@quad.sysarch.com>
>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
>> map conveys "I am building a list" (because it returns a list).
BM> So does delete. Would you object to delete in void context?
but delete conveys the message of doing a side effect. its return value
is nice sugar but isn't needed (amazing how often i show use of delete's
return value and how few know it). map's history (yes, history isn't
taught much) is from building a list from a list. its primary purpose is
building that list and that is what is says to the reader. i always
teach code is for people, not computers. we all can use things in ways
that were unintended but we try to stay away from them for fear of
confusing readers. given that map has the for modifier for use when
doing side effects, that is a better semantic match for that case. note
that for modifier was added after perl5 was first out. map could have
been used for that but given the inefficiency then of throwing out the
list (not true anymore but still) and wrong semantics, it was a good
addition to the language. so why not use it for its purpose? for means
you are doing some side effects in the expression. map means you are
building a list and supposedly not doing side effects.
this is similar to using ?: with side effects. it is a bad idea even if
you get the syntax right (using parens with assignments). ?: is meant to
return a value and not for side effects. perl allows any legit
expression including side effect ones anywhere. that doesn't mean it is
a good idea to do that.
code is for people, not computers.
code is for OTHER people, not yourself.
code is the record of the logical decisions you made when creating this
program.
code is where you can let your ego shine in the reflection of those who
read your code.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 27 Jan 2010 00:41:26 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: print array with separator?
Message-Id: <4b5f7da7$0$22934$e4fe514c@news.xs4all.nl>
Tad McClellan wrote:
> map conveys "I am building a list" (because it returns a list).
IIRC: unless in void context.
(as one of the recent optimizations)
Not that I like to see map used in void context,
I rather see a for loop.
Just joking:
perl -wle '
my @x = -3 .. 3;
grep { ++$_; 0 } @x;
print for @x;
'
-2
-1
0
1
2
3
4
(huh? C<grep ++$_, -3..3> doesn't complain about readonly-ness)
--
Ruud
------------------------------
Date: Tue, 26 Jan 2010 19:07:34 -0500
From: sreservoir <sreservoir@gmail.com>
Subject: Re: print array with separator?
Message-Id: <hjo04j$38d$1@speranza.aioe.org>
On 1/26/2010 6:41 PM, Dr.Ruud wrote:
> Tad McClellan wrote:
>
>> map conveys "I am building a list" (because it returns a list).
>
> IIRC: unless in void context.
> (as one of the recent optimizations)
not that that really matters.
> Not that I like to see map used in void context,
> I rather see a for loop.
>
>
> Just joking:
>
> perl -wle '
> my @x = -3 .. 3;
> grep { ++$_; 0 } @x;
> print for @x;
> '
> -2
> -1
> 0
> 1
> 2
> 3
> 4
>
perl -wle 'my @a = -3 .. 3; map { --$_; () } @a; print for @a'
not much worse, but still hell for readability.
> (huh? C<grep ++$_, -3..3> doesn't complain about readonly-ness)
(huh? it's rw pass-by-ref)
--
"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
------------------------------
Date: Wed, 27 Jan 2010 01:42:47 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: print array with separator?
Message-Id: <n9i437-t3l.ln1@osiris.mauzo.dyndns.org>
Quoth sreservoir <sreservoir@gmail.com>:
> On 1/26/2010 6:41 PM, Dr.Ruud wrote:
>
> > (huh? C<grep ++$_, -3..3> doesn't complain about readonly-ness)
>
> (huh? it's rw pass-by-ref)
$_ ought to be an alias to a constant.
~% perl -e'map $_++, -3..3'
~% perl -e'map $_++, -3, -2, -1, 0, 1, 2, 3'
Modification of a read-only value attempted at -e line 1.
~%
In fact, it seems perl precomputes the range at compile-time, puts the
results in a constant array, but forgets to make the elements constant:
~% perl -e'map $_++, -3..3'
a <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
7 <|> mapwhile(other->8)[t5] vK ->a
6 <@> mapstart K ->7
3 <0> pushmark s ->4
- <1> null lK/1 ->4
9 <1> postinc[t1] sK/1 ->7
- <1> ex-rv2sv sKRM/1 ->9
8 <$> gvsv(*_) s ->9
5 <1> rv2av lKPM/1 ->6
4 <$> const(AV ) s ->5
which has some side-effects which make this definitely a bug:
~% perl -E'for (1..2) { map {say ++$_} -2..2 }'
-1
0
1
2
3
0
1
2
3
4
~%
Ben
------------------------------
Date: Tue, 26 Jan 2010 17:40:01 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: strip all but second second line from bottom and then strip that!!!!
Message-Id: <286b6607-7c84-4796-8500-0d0b1a0ae798@g29g2000yqe.googlegroups.com>
On Jan 26, 1:37=A0pm, "yelipolok<k...@aol.com>"
<bbeas...@beasleyhull.com> wrote:
> I cannot figure it out, but I know it's very simple for perl.
>
> Here's the text, below the cut mark. =A0There's a typical \n at the end
> of each line.
>
> --
> info depth 9
> info depth 9
> info depth 9 seldepth 30 score cp 31 lowerbound time 59 nodes 80142
> nps 1358000 pv f6f3 e2f3
> info depth 9
> info depth 9 seldepth 30 score cp 17 =A0time 61 nodes 82240 nps 1348000
> pv f6f3 e2f3 c6d4 f3e3
> info depth 10
> info depth 10 seldepth 32 score cp 25 lowerbound time 91 nodes 126058
> nps 1385000 pv f6f3 e2f3
> info depth 10
> info depth 10 seldepth 32 score cp 33 lowerbound time 111 nodes 156296
> nps 1408000 pv f6f3 e2f3
> info depth 10
> info depth 10 seldepth 33 score cp 34 =A0time 144 nodes 205129 nps
> 1424000 pv f6f3 e2f3 c6d4 f3e3
> info depth 10 seldepth 33 score cp 34 =A0time 154 nodes 216834 nps
> 1408000 pv f6f3 e2f3 c6d4 f3e3
> bestmove f6f3 ponder e2f3
> --
>
> I want to strip it all EXCEPT for the the line second from bottom and
> then just the part from "pv to the end of line"
>
> Result being: =A0 =A0f6f3 e2f3 c6d4 f3e3
perl -ne 'if(eof){($_=3D$l) =3D~s /1408000 pv //;print }else{$l=3D$_}'
infile
--
Charles DeRykus
------------------------------
Date: Tue, 26 Jan 2010 13:37:37 -0800 (PST)
From: "yelipolok<kjl@aol.com>" <bbeasley@beasleyhull.com>
Subject: strip all but second second line from bottom and then strip that!!!!
Message-Id: <16cc33d8-c7dd-4d69-9631-084249014513@l11g2000yqb.googlegroups.com>
I cannot figure it out, but I know it's very simple for perl.
Here's the text, below the cut mark. There's a typical \n at the end
of each line.
--
info depth 9
info depth 9
info depth 9 seldepth 30 score cp 31 lowerbound time 59 nodes 80142
nps 1358000 pv f6f3 e2f3
info depth 9
info depth 9 seldepth 30 score cp 17 time 61 nodes 82240 nps 1348000
pv f6f3 e2f3 c6d4 f3e3
info depth 10
info depth 10 seldepth 32 score cp 25 lowerbound time 91 nodes 126058
nps 1385000 pv f6f3 e2f3
info depth 10
info depth 10 seldepth 32 score cp 33 lowerbound time 111 nodes 156296
nps 1408000 pv f6f3 e2f3
info depth 10
info depth 10 seldepth 33 score cp 34 time 144 nodes 205129 nps
1424000 pv f6f3 e2f3 c6d4 f3e3
info depth 10 seldepth 33 score cp 34 time 154 nodes 216834 nps
1408000 pv f6f3 e2f3 c6d4 f3e3
bestmove f6f3 ponder e2f3
--
I want to strip it all EXCEPT for the the line second from bottom and
then just the part from "pv to the end of line"
Result being: f6f3 e2f3 c6d4 f3e3
Thanks
------------------------------
Date: Tue, 26 Jan 2010 13:52:26 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: strip all but second second line from bottom and then strip that!!!!
Message-Id: <bqoul551jggop6e5v04q4um3uhg2t04m0c@4ax.com>
"yelipolok<kjl@aol.com>" <bbeasley@beasleyhull.com> wrote:
>I cannot figure it out, but I know it's very simple for perl.
>
>Here's the text, below the cut mark. There's a typical \n at the end
>of each line.
>
>--
[...]
>info depth 10 seldepth 33 score cp 34 time 144 nodes 205129 nps
>1424000 pv f6f3 e2f3 c6d4 f3e3
>info depth 10 seldepth 33 score cp 34 time 154 nodes 216834 nps
>1408000 pv f6f3 e2f3 c6d4 f3e3
>bestmove f6f3 ponder e2f3
Open the file, slurp the text into an array @lines, grab
$lines[@lines-1], and split on space character like
(undef, undef, $result) = split / /, $lines[@lines-1], 3;
jue
------------------------------
Date: Tue, 26 Jan 2010 15:11:37 -0800
From: sln@netherlands.com
Subject: Re: strip all but second second line from bottom and then strip that!!!!
Message-Id: <9ctul59n2mp6p1snpr3lgmkquf4a3583bh@4ax.com>
On Tue, 26 Jan 2010 13:37:37 -0800 (PST), "yelipolok<kjl@aol.com>" <bbeasley@beasleyhull.com> wrote:
This is an initial interpretation. Depends on what you mean "EXCEPT ..."
-sln
--------------
use strict;
use warnings;
{
local $/;
print $1 if <DATA> =~ /.*pv\s*([a-f0-9 ]+)$/ims;
}
__DATA__
>I cannot figure it out, but I know it's very simple for perl.
>
>Here's the text, below the cut mark. There's a typical \n at the end
>of each line.
>
>--
>info depth 9
>info depth 9
>info depth 9 seldepth 30 score cp 31 lowerbound time 59 nodes 80142
>nps 1358000 pv f6f3 e2f3
>info depth 9
>info depth 9 seldepth 30 score cp 17 time 61 nodes 82240 nps 1348000
>pv f6f3 e2f3 c6d4 f3e3
>info depth 10
>info depth 10 seldepth 32 score cp 25 lowerbound time 91 nodes 126058
>nps 1385000 pv f6f3 e2f3
>info depth 10
>info depth 10 seldepth 32 score cp 33 lowerbound time 111 nodes 156296
>nps 1408000 pv f6f3 e2f3
>info depth 10
>info depth 10 seldepth 33 score cp 34 time 144 nodes 205129 nps
>1424000 pv f6f3 e2f3 c6d4 f3e3
>info depth 10 seldepth 33 score cp 34 time 154 nodes 216834 nps
>1408000 pv f6f3 e2f3 c6d4 f3e3
>bestmove f6f3 ponder e2f3
>--
>
>I want to strip it all EXCEPT for the the line second from bottom and
>then just the part from "pv to the end of line"
>
>Result being: f6f3 e2f3 c6d4 f3e3
>
>Thanks
------------------------------
Date: Tue, 26 Jan 2010 16:31:03 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: When to use "use strict;"?
Message-Id: <slrnhlur2n.2n2.tadmc@tadbox.sbcglobal.net>
Charlton Wilbur <cwilbur@chromatico.net> wrote:
>>>>>> "PY" == Peng Yu <pengyu.ut@gmail.com> writes:
>
> PY> I was told to always use "use strict;" in another thread in this
> PY> newsgroup. However, I checked Programming Perl. It seems that
> PY> "use strict" is not necessary for small program.
>
> If you need to ask, you aren't experienced enough to know when you don't
> need it. And if you are experienced enough to know when you don't need
> it, you've also been bitten by stupid bugs often enough to always use it
> anyway.
Beautifully said!
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Tue, 26 Jan 2010 17:45:18 -0500
From: sreservoir <sreservoir@gmail.com>
Subject: Re: When to use "use strict;"?
Message-Id: <hjnra9$sfq$1@speranza.aioe.org>
On 1/26/2010 11:23 AM, Charlton Wilbur wrote:
>>>>>> "PY" == Peng Yu<pengyu.ut@gmail.com> writes:
>
> PY> I was told to always use "use strict;" in another thread in this
> PY> newsgroup. However, I checked Programming Perl. It seems that
> PY> "use strict" is not necessary for small program.
>
> If you need to ask, you aren't experienced enough to know when you don't
> need it. And if you are experienced enough to know when you don't need
> it, you've also been bitten by stupid bugs often enough to always use it
> anyway.
or need to not have it. but that's what lexical pragmata are for.
--
"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
------------------------------
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 2791
***************************************