[33145] in Perl-Users-Digest
Perl-Users Digest, Issue: 4424 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 1 00:09:19 2015
Date: Thu, 30 Apr 2015 21:09:05 -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 Thu, 30 Apr 2015 Volume: 11 Number: 4424
Today's topics:
"zero-copy" parsing of in-memory data <rweikusat@mobileactivedefense.com>
Re: "zero-copy" parsing of in-memory data <rweikusat@mobileactivedefense.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <news@todbe.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <m@rtij.nl.invlalid>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl mentificium@gmail.com
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <rweikusat@mobileactivedefense.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <news@lawshouse.org>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <kaz@kylheku.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <jurgenex@hotmail.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <kaz@kylheku.com>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl mentificium@gmail.com
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <kaz@kylheku.com>
Re: How do I use "when" to check for "one of two option <m@rtij.nl.invlalid>
Re: How do I use "when" to check for "one of two option <bauhaus@futureapps.invalid>
Re: How do I use "when" to check for "one of two option <rweikusat@mobileactivedefense.com>
Re: How do I use "when" to check for "one of two option <bauhaus@futureapps.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Apr 2015 22:20:16 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: "zero-copy" parsing of in-memory data
Message-Id: <871tj1s48f.fsf@doppelsaurus.mobileactivedefense.com>
NB: This is loosely based on techniques described in chapter 8 of
'Higher Order Perl', a book well worth of having provided one is capable
of restricting oneself to reading about the concepts instead of getting
distracted by the typically grotty code examples.
perl maintains a 'current matching position' (=> perldoc -f pos) when
matching strings against regexes. Normally, the position is reset to 0
after each match but this can be avoided by adding the 'g' (keep
position after a successful match) and 'c' (don't reset position after a
failed match) flags. Furhter, a \G assertion is available which anchors
the match at the current position even when trying to match a different
regex. As also explained in 'perldoc perlop', this can be used to take a
string apart piece by piece ('lexical analysis').
A match operator not bound to a specific variable defaults to matching against
$_ which is a dynamically scoped symbol/ variable ('global').
Subroutine arguments are always passed by reference, eg,
invoking a subroutine as
subito($a)
makes the actual scalar $a available as first argument of the
subroutine.
It's possible to bind 'an entity' to a 'package-global' name by assiging
a reference to the entity to the corresponding glob. Such an assignment
can use 'local' to restrict visibility of the binding to 'subroutines
called from within the current block' (and subroutines called from such
subroutines). The value previously bound to the name is saved and
automatically restored once the binding goes out of scope. A nice
side-effect of that is that it can be used to make an argument to a
function accessible by name without copying its value, as the more
common-place
my $bla = $_[0]
would do.
Pulling this together, it's possible to start a top-level parsing
routine like this
sub parse_json
{
local *_ = \$_[0];
which will make the first argument accessible as $_ without copying the
value and then descent into a recursive descent parser operating on $_,
example routine (starting position is on the leading "):
sub parse_string()
{
my $s;
skip_char();
{
/\G"/gc && last;
/\G([^"\\]+)/gc && do {
$s .= decode('UTF-8', $1);
redo;
};
/\G\\(["\/\\])/gc && do {
$s .= $1;
redo;
};
/\G\\([bfnrt])/gc && do {
$s .= $json_escapes{$1};
redo;
};
/\G\\u/gc && do {
$s .= parse_u_escapes();
redo;
};
parser_error('weird shit in string');
}
p_alloc('string \'%s\'', $s);
return $s;
}
------------------------------
Date: Thu, 30 Apr 2015 23:14:41 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: "zero-copy" parsing of in-memory data
Message-Id: <87wq0tqn5a.fsf@doppelsaurus.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
[preliminaries]
> example routine (starting position is on the leading "):
There are (at least) two bugs in this, namely,
> sub parse_string()
> {
> my $s;
>
> skip_char();
A $s = '' should appear so that empty strings are returned as emtpy
strings and not as undef/
[...]
A check for 'end of input' should appear here for more sensible error
messages, eg
die('unexpected EOF') if pos() == length();
> parser_error('weird shit in string');
> }
------------------------------
Date: Tue, 28 Apr 2015 23:37:08 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <mhpu4q$ipc$1@dont-email.me>
On 4/28/2015 18:50, mentificium@gmail.com wrote:
> On Tuesday, April 28, 2015 at 6:28:46 PM UTC-7, Juergen Exner wrote:
>
> Yes, there is. While I was writing the program,
> I had those two items _in_ the program. But
> then I removed those two lines from the mind.pl
> program so that it would be as simple as possible
> and still work.
Doesn't make sense - those two lines will save you lots of
debug time. Don't take them out until you have a tested
product to release.
> If anyone knows why I should not use Ctrl+C
> for escaping from the Main AI program loop,
> please let me know. I am glad not only that
> Perl uses "die" to halt a program, but also
> I like reading in my Perl books that the
> default top-level package in a Perl program
> is "main::" even if it has no actual name.
I've always used 'q' or 'quit' to exit a program.
If you're parsing character by character, that could be an issue,
but if you have a control mode in addition to an input mode, then
'q' or 'quit' should work fine.
Ctrl-C aborts the program, so normally you would have to trap the
Ctrl-C signal so you can clean up things and exit gracefully.
------------------------------
Date: Wed, 29 Apr 2015 09:40:44 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <sge61c-2f2.ln1@news.rtij.nl>
On Tue, 28 Apr 2015 23:37:08 -0700, $Bill wrote:
> On 4/28/2015 18:50, mentificium@gmail.com wrote:
>> On Tuesday, April 28, 2015 at 6:28:46 PM UTC-7, Juergen Exner wrote:
>>
>> Yes, there is. While I was writing the program,
>> I had those two items _in_ the program. But then I removed those two
>> lines from the mind.pl program so that it would be as simple as
>> possible and still work.
>
> Doesn't make sense - those two lines will save you lots of debug time.
> Don't take them out until you have a tested product to release.
No, don't take them out at all.
M4
------------------------------
Date: Wed, 29 Apr 2015 21:49:06 -0700 (PDT)
From: mentificium@gmail.com
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <597a3f7d-6e9a-438b-b19f-58fc2e6e5a32@googlegroups.com>
#!/usr/bin/perl
use strict; # PERL by Example (2015), p. 77
use warnings; # PERL by Example (2015), p. 85
our $IQ = 0; # PERL by Example (2015), p. 689
sub sensorium; # PERL by Example p. 351 Forward declaration
sub think; # PERL by Example p. 351 Forward declaration
while ($IQ < 8) { # PERL by Example (2015), p. 190
sensorium(); # PERL by Example p. 350: () empty parameter list
think(); # PERL by Example p. 350: () empty parameter list
} # End of main loop calling AI subroutines
sub sensorium() { # Start sensory input.
print " Sensorium: Enter new IQ: ";
$IQ = <STDIN>; # PERL by Example (2015), p. 50
} # End of sensorium subroutine.
sub think() { # Start showing output as if generated by thinking.
print "Think: My IQ is now $IQ";
} # End of mind.pl program for coding Strong AI in Perl
------------------------------
Date: Thu, 30 Apr 2015 14:55:24 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <87egn1sotv.fsf@doppelsaurus.mobileactivedefense.com>
mentificium@gmail.com writes:
> #!/usr/bin/perl
> use strict; # PERL by Example (2015), p. 77
> use warnings; # PERL by Example (2015), p. 85
> our $IQ = 0; # PERL by Example (2015), p. 689
> sub sensorium; # PERL by Example p. 351 Forward declaration
> sub think; # PERL by Example p. 351 Forward declaration
> while ($IQ < 8) { # PERL by Example (2015), p. 190
> sensorium(); # PERL by Example p. 350: () empty parameter list
> think(); # PERL by Example p. 350: () empty parameter list
> } # End of main loop calling AI subroutines
> sub sensorium() { # Start sensory input.
> print " Sensorium: Enter new IQ: ";
> $IQ = <STDIN>; # PERL by Example (2015), p. 50
> } # End of sensorium subroutine.
> sub think() { # Start showing output as if generated by thinking.
> print "Think: My IQ is now $IQ";
> } # End of mind.pl program for coding Strong AI in Perl
JFTR: The idea behind 'comments' is that they can be used to add
background information considered to be helpful for understanding the
code to the code. Even then, they're best used sparingly as 'people in a
hurry' are bound to take a chunk of code, copy'n'paste it elsehwere,
invert the complete logic but leave all embedded comments as they were
(motto: There is already a comment associated with this line of code,
hence, the formal requirements have been met, so why reinvent the wheel
and write a new one).
A commenting-style like the one you are using above just ends up making
the important parts of the text (the code) almost completely unreadable.
------------------------------
Date: Thu, 30 Apr 2015 15:01:37 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <n4adncYVOb5cqN_InZ2dnUU78ekAAAAA@giganews.com>
On 30/04/15 05:49, mentificium@gmail.com wrote:
> #!/usr/bin/perl
> use strict; # PERL by Example (2015), p. 77
Why are you posting this stuff? Do you have a problem with it that
you'd like our help solving? Or do you think it's educational, clever
or amusing? (It's none of those things).
--
Henry Law Manchester, England
------------------------------
Date: Thu, 30 Apr 2015 14:28:18 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <20150430072719.864@kylheku.com>
On 2015-04-30, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> mentificium@gmail.com writes:
>> #!/usr/bin/perl
>> use strict; # PERL by Example (2015), p. 77
>> use warnings; # PERL by Example (2015), p. 85
>> our $IQ = 0; # PERL by Example (2015), p. 689
>> sub sensorium; # PERL by Example p. 351 Forward declaration
>> sub think; # PERL by Example p. 351 Forward declaration
>> while ($IQ < 8) { # PERL by Example (2015), p. 190
>> sensorium(); # PERL by Example p. 350: () empty parameter list
>> think(); # PERL by Example p. 350: () empty parameter list
>> } # End of main loop calling AI subroutines
>> sub sensorium() { # Start sensory input.
>> print " Sensorium: Enter new IQ: ";
>> $IQ = <STDIN>; # PERL by Example (2015), p. 50
>> } # End of sensorium subroutine.
>> sub think() { # Start showing output as if generated by thinking.
>> print "Think: My IQ is now $IQ";
[ snip ]
> A commenting-style like the one you are using above just ends up making
> the important parts of the text (the code) almost completely unreadable.
"Important parts", haha!
The external references in the comments are all that is potentially valuable in
that moronic rubbish.
------------------------------
Date: Thu, 30 Apr 2015 08:16:26 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <jdh4ka50b31c2k4tkhuejkim6nto6jmqkk@4ax.com>
mentificium@gmail.com wrote:
>#!/usr/bin/perl
You are missing
use strict;
use warnings;
>use strict; # PERL by Example (2015), p. 77
>use warnings; # PERL by Example (2015), p. 85
Oh, wait, you are not. They are just buried in useless junk that is
masqueraded as comments.
>our $IQ = 0; # PERL by Example (2015), p. 689
>sub sensorium; # PERL by Example p. 351 Forward declaration
[snipped another 10 lines of gibberish]
What on earth are you trying to do? That stuff is unreadable.
Do you have a question about your code? It is so elementary, any
introduction into Perl will cover it in the first 10 pages.
>} # End of mind.pl program for coding Strong AI in Perl
I guess if you can cover AI in Perl in less than 20 lines of trivial
code, then either Perl is extremely powerful or your AI is extremely not
powerful.
jue
------------------------------
Date: Thu, 30 Apr 2015 15:33:50 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <20150430083224.515@kylheku.com>
On 2015-04-30, Henry Law <news@lawshouse.org> wrote:
> On 30/04/15 05:49, mentificium@gmail.com wrote:
>> #!/usr/bin/perl
>> use strict; # PERL by Example (2015), p. 77
>
> Why are you posting this stuff? Do you have a problem with it that
> you'd like our help solving? Or do you think it's educational, clever
> or amusing? (It's none of those things).
Also, completely undocumented:
- what are the detailed requirements which it implements?
- what is the functional specification?
- what problem does it solve? what are the inputs and expected outputs?
where are the test cases for detecting a regression in the behavior?
------------------------------
Date: Thu, 30 Apr 2015 18:27:37 -0700 (PDT)
From: mentificium@gmail.com
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <1ad730fd-67db-4417-8aa6-4e1540727584@googlegroups.com>
On Thursday, April 30, 2015 at 6:55:30 AM UTC-7, Rainer Weikusat wrote:
> mentificium@gmail.com writes:
> > #!/usr/bin/perl
> > use strict; # PERL by Example (2015), p. 77
> > use warnings; # PERL by Example (2015), p. 85
> [...]
> JFTR: The idea behind 'comments' is that they can
> be used to add background information considered to
> be helpful for understanding the code to the code.
http://ai.neocities.org/AiSteps.html is where I am
using Perl code comments to synchronize the AI Steps
with pertinent page-numbers in the new, January 2015
Fifth Edition of "PERL by Example."
Henry Law posted upthread:
> Why are you posting this stuff?
As stated in the original thread title
("Learn AI and Perl simultaneously"),
I am trying to let Perl newbies jump
right in to Perl coding by building the
same Perl AI that I am building.
http://mind.sourceforge.net/aisteps.html
is a previous version of "AI Steps" but
without the incremental Perl code of the
http://ai.neocities.org/AiSteps.html webpage.
The Perl AI is a third-generation Mentifex AI,
after Mind.REXX (1994) and MindForth (1998-2015).
Any programmer can select a language in which
to implement the "AI Steps", while the snippets
of Perl code provide a glimpse of what to expect.
Today Thurs.30.APRIL.2015 I suddenly realized
that the "AI Steps" with Perl code will let
Netizens decide where they might like to
branch off or "fork" away from my own AI code.
They may also let someone decide to implement
a missing mind-module, such as perhaps the
VisRecog visual-recognition module.
Henry Law wrote:
> Do you have a problem with it that
> you'd like our help solving?
I would like your help in propagating
the open-source free-of-charge AI design.
If problems arise, I would like help in
solving them.
Henry Law ipse dixit:
> Or do you think it's educational, clever
> or amusing? [...]
Mostly educational. I also sincerely believe
that the AI discussion spices up and enhances
the interest-value of the newsgroup. In some
other newsgroups, like the Ruby one (which
I was instrumental in founding, by voting),
Mentifex-bashers hounded me out of the group,
and then other people said that they missed me.
Juergen Exner addressed the crowd:
[...]
> I guess if you can cover AI in Perl in
> less than 20 lines of trivial code, then
> either Perl is extremely powerful or your
> AI is extremely not powerful.
http://ai.neocities.org/AiSteps.html
is a series of "AI Steps" in coding Perl AI.
Certainly the early Steps look trivial, but
they go right to the heart of the AI matter.
Similar AI Minds already think and do automated
reasoning in English, German +/- Russian.
Kaz Kylheku chimed in:
> Also, completely undocumented:
http://mind.sourceforge.net/m4thuser.html
http://code.google.com/p/mindforth/wiki/UserManual
> - what are the detailed requirements which it implements?
It implements the setting up of experiential memory
channels and linguistic superstructures for AI thinking.
> - what is the functional specification?
At first, it only deals with inputs of
Subject + Verb + Object in English.
It learns new English words, one at a time.
(No input sentence should be totally new words.)
> - what problem does it solve?
It solves the problem of how an artificial Mind
caqn think in natural language and infer things.
> what are the inputs and expected outputs?
The inputs will be simple Subject-Verb-Object
English sentences, also sometimes "yes" or "no"
in response to inferences being validated.
> where are the test cases for detecting
> a regression in the behavior?
Sorry, I don't understand that question.
Bye for now,
Arthur T. Murray
--
http://www.nlg-wiki.org/systems/User:Arthur_T._Murray
------------------------------
Date: Fri, 1 May 2015 02:04:49 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <20150430184751.27@kylheku.com>
On 2015-05-01, mentificium@gmail.com <mentificium@gmail.com> wrote:
> Kaz Kylheku chimed in:
>> Also, completely undocumented:
>
> http://mind.sourceforge.net/m4thuser.html
>
> http://code.google.com/p/mindforth/wiki/UserManual
>
>> - what are the detailed requirements which it implements?
> It implements the setting up of experiential memory
> channels and linguistic superstructures for AI thinking.
That is not a detailed requirement.
>> - what is the functional specification?
> At first, it only deals with inputs of
> Subject + Verb + Object in English.
> It learns new English words, one at a time.
> (No input sentence should be totally new words.)
>
>> - what problem does it solve?
> It solves the problem of how an artificial Mind
> caqn think in natural language and infer things.
This is vague.
Can you show some input/output pairs from an actual run of this program which
demonstrate the processing of natural language, and consequent inference?
What is a concrete example of the sort of thing that it can infer?
>> what are the inputs and expected outputs?
> The inputs will be simple Subject-Verb-Object
Will be? Aren't now? So when?
But there is code now which is claimed to be "AI".
Can you give *conrete examples* (ASCII text) of inputs, and their
expected outputs?
> English sentences, also sometimes "yes" or "no"
> in response to inferences being validated.
(Why only simple sentences? A rigid SVO syntax is not "natural language";
it is a computer command language.)
>> where are the test cases for detecting
>> a regression in the behavior?
>
> Sorry, I don't understand that question.
Maybe you should feed the question to your so-called AI program, hmm?
If fifty years of programming, it's amazing that you haven't heard of
"regression" and "test case".
The question means, how are you validating the correctness of the code, that it
is working?
If you make a change which introduces a bug (something stops working:
regression), how will you know?
By what process do you try to ensure that, as you extend the program, it
continues to be able to do everything that it did previously: handle all the
same inputs and produce the same outputs as before?
------------------------------
Date: Wed, 29 Apr 2015 09:42:42 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <ike61c-2f2.ln1@news.rtij.nl>
On Tue, 28 Apr 2015 16:35:03 +0100, Rainer Weikusat wrote:
> Martijn Lievaart <m@rtij.nl.invlalid> writes:
>> On Thu, 23 Apr 2015 06:58:29 +0200, gamo wrote:
>>
>>>> when (['a','A']) {action1;}
>>
>>> when (/a/i) { }
>>
>> Those are not the same. You would need /^a$/i for that.
>
> Even this isn't strictly true as $ either matches the end of the string
> or a \n which is its last character, cf
>
> perl -e 'print "a\n" =~ /^a$/'
>
> /^a\z/i
>
> would need to be used to match only a or A.
True, thanks for the correction.
(so I have been making this mistake in this context all my perl life :-( )
M4
------------------------------
Date: Wed, 29 Apr 2015 11:36:10 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <mhq8ka$oa7$1@dont-email.me>
On 29.04.15 09:42, Martijn Lievaart wrote:
> On Tue, 28 Apr 2015 16:35:03 +0100, Rainer Weikusat wrote:
>> /^a\z/i
>>
>> would need to be used to match only a or A.
>
> True, thanks for the correction.
>
> (so I have been making this mistake in this context all my perl life :-( )
To be fair, Perl's RE support is influenced by the both simplistic and
vague as well as flexible features of I/O via Unix/C and then PC/C
facilities ("Everything is just a..., but, you know, \n isn't just...,
and then \r neither, because ... Well, just chop and, oh, wait, chomp
and move on.") So, rather than blaming yourself for accidents of
computing history (cf. Douglas Crockford's talks), get paid for these
design mistakes as a necessity of life. They'll stay in any case.
------------------------------
Date: Wed, 29 Apr 2015 20:31:37 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <87twvywx2e.fsf@doppelsaurus.mobileactivedefense.com>
"G.B." <bauhaus@futureapps.invalid> writes:
> On 29.04.15 09:42, Martijn Lievaart wrote:
>> On Tue, 28 Apr 2015 16:35:03 +0100, Rainer Weikusat wrote:
>
>>> /^a\z/i
>>>
>>> would need to be used to match only a or A.
>>
>> True, thanks for the correction.
>>
>> (so I have been making this mistake in this context all my perl life :-( )
[...]
> ("Everything is just a..., but, you know, \n isn't just...,
> and then \r neither, because ... Well, just chop and, oh, wait, chomp
> and move on.") So, rather than blaming yourself for accidents of
> computing history (cf. Douglas Crockford's talks), get paid for these
> design mistakes as a necessity of life. They'll stay in any case.
Could you perhaps enlighten about the relation between "\r, \n, chop and
chomp" and "Perl regex anchors"? And what is "everything" which "\n
isn't and neither is \r" (minus the obvious "everything is neither \n
nor \r except if its \n or \r" which seems a little silly). And what
about "chop and chomp"?
Some background: Perl4 had chop but not chomp and it supported
configuring the input record separator via assignment to $/. chop can be
used to remove any kind of input record separator provided it's a
single character but $/ is not restricted to single characters. Further,
'text fields' may end with incomplete records, not the least because not
all text editors always append a traling \n in case there isn't one upon
saving. But chop always removes the last character, no matter what it
is.
A function 'remove input record separator at end of input' could be
defined as
sub chop_sep
{
$_[0] =~ s/$\/\z//;
}
or
sub chop_sep
{
s/$\/\z// for @_;
}
Something similar was added as 'chomp' to Perl5. What's wrong with that?
------------------------------
Date: Thu, 30 Apr 2015 11:58:54 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <mhsub0$1at$1@dont-email.me>
On 29.04.15 21:31, Rainer Weikusat wrote:
> "G.B." <bauhaus@futureapps.invalid> writes:
>> On 29.04.15 09:42, Martijn Lievaart wrote:
>>> On Tue, 28 Apr 2015 16:35:03 +0100, Rainer Weikusat wrote:
>>
>>>> /^a\z/i
>>>>
>>>> would need to be used to match only a or A.
>>>
>>> True, thanks for the correction.
>>>
>>> (so I have been making this mistake in this context all my perl life :-( )
>
> [...]
>
>> ("Everything is just a..., but, you know, \n isn't just...,
>> and then \r neither, because ... Well, just chop and, oh, wait, chomp
>> and move on.") So, rather than blaming yourself for accidents of
>> computing history (cf. Douglas Crockford's talks), get paid for these
>> design mistakes as a necessity of life. They'll stay in any case.
>
> Could you perhaps enlighten about the relation between "\r, \n, chop and
> chomp" and "Perl regex anchors"? And what is "everything"
I think I could, but suffice it to say that the writer of an RE
will hardly ever be concerned with \n, say, once both the OS
and its programs use typed data (as some have done):
As a programmer tasked with handling lines of text, then,
you would never see those "special characters" signalling
the lines. The end of the line is then just that and
is not related to some set of characters. The modifiers
/m and /s then become meaningless at the level of characters.
And, arguably, chop or chomp will be rendered useless.
There would be no point in having them as their work is
already done!
So, as a first observation, REs can first be used to turn
input streams into meaningful units, and would thereafter
be used to study those units. Sometimes the two steps are
merged into one, as the sufficiently trained readers of Perl
programs will recognized with ease, won't they?
Them characters is what you get to see if "everything is just
bytes", streams of them. To turn chunks of bytes into meaningful
units, a programmer will have to use whatever is being offered
by Unix or DOS(-oid) features. In part, this was inherited by Perl,
I think. (Different conventions of using those "special characters"
continue to make porting software surprisingly difficult.(*))
I remember once using REs in order to find places in a stream of
data transferred as video text ("binary", really). So yes,
REs with special characters in them looked like very useful,
but that was really a hack and it did not involve _any_
ends-of-line or record separators or whatever is associated with
chopping lines at special characters: what did work was just bytes
and pattern matching.
So, both the lack of typed data, and then a workaround(**) based
on special characters, lead to Perl REs, as a consequence of Unix
style. Thus they emphasize certain characters like 'n', 'v', 'r',
and treat them specially in special context, too, as seen.
That does not simplify the task, or clarify the expression, IMHO.
___
(*) Just recently observed: scripts for testing and configuration
used dos2unix(1) solely for handling EOL; the program needs
some efforts for translating on Mac+BSD, so I finally replaced
that with either NOP script or one that employs tr(1) as needed.
(**) a.k.a. brilliant solution, leaving it to the programmer.
------------------------------
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 4424
***************************************