[33146] in Perl-Users-Digest
Perl-Users Digest, Issue: 4425 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 2 18:09:18 2015
Date: Sat, 2 May 2015 15: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 Sat, 2 May 2015 Volume: 11 Number: 4425
Today's topics:
Re: "zero-copy" parsing of in-memory data <gravitalsun@hotmail.foo>
Re: -d test recognizes Windows 8.1 SYMLINKD as being di <see.my.sig@for.my.address>
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl mentificium@gmail.com
Re: Attn: Perl Newbies! Learn AI and Perl simultaneousl <news@lawshouse.org>
Folding dirpath into wildcard for fileglob. <see.my.sig@for.my.address>
Re: Folding dirpath into wildcard for fileglob. <rweikusat@mobileactivedefense.com>
Re: Folding dirpath into wildcard for fileglob. <gravitalsun@hotmail.foo>
Re: Folding dirpath into wildcard for fileglob. <news@todbe.com>
Re: Folding dirpath into wildcard for fileglob. <rweikusat@mobileactivedefense.com>
Re: Folding dirpath into wildcard for fileglob. <news@todbe.com>
Re: Folding dirpath into wildcard for fileglob. <rweikusat@mobileactivedefense.com>
Re: Folding dirpath into wildcard for fileglob. <gamo@telecable.es>
Re: Folding dirpath into wildcard for fileglob. <news@todbe.com>
Re: Folding dirpath into wildcard for fileglob. <gamo@telecable.es>
Re: How do I use "when" to check for "one of two option <gamo@telecable.es>
Re: How do I use "when" to check for "one of two option <rweikusat@mobileactivedefense.com>
Re: How to "unuse" Perl modules <scorpionjs@yahoo.com>
Re: How to "unuse" Perl modules <gravitalsun@hotmail.foo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 01 May 2015 12:48:10 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: "zero-copy" parsing of in-memory data
Message-Id: <mhvi5c$pan$1@news.grnet.gr>
On 1/5/2015 00:20, Rainer Weikusat wrote:
> 'Higher Order Perl',
This is the best Perl book for me. I think it will also help people
using other languages as well
------------------------------
Date: Fri, 01 May 2015 04:21:38 -0700
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Re: -d test recognizes Windows 8.1 SYMLINKD as being directory???
Message-Id: <g9GdnQDuz6ki_N7InZ2dnUVZ572dnZ2d@giganews.com>
On 4/27/2015 4:44 AM, gamo wrote:
> El 14/04/15 a las 15:08, Robbie Hatley escribió:
>> The item mentioned, "gargoyle", isn't really a directory at all,
>> but a Windows "SYMLINKD" object. But Perl's -d test recognizes
>> it as being a "directory" anyway. That's problematic, because
>> THIS:
>>
>> /rhe/test-zone/tarsier/gargoyle
>>
>> is just a SYMLINKD leading back to THIS:
>>
>> /rhe/test-zone
>>
>> Which would have caused infinite recursion in RecurseDirs.
>> Good thing I thought to include a check for inode reusage:
>
> Try to play with 'if (not -l $entry){ }' because -l is tailored
> to tell you if it's a simlink, at least in linux.
Yep, I ended up doing that, because in Windows 8.1, you can have:
1. Items which are neither links nor directories (plain files)
2. Items which are links but not directories (links to files)
3. Items which are directories but not links (normal directories)
4. Items which are directories AND links (called "SYMLINKD")
So I eventually re-wrote my "GetFiles" subroutine (returns ref to
array of file records) so that it segregates files into those 4
categories:
sub GetFiles (;$$$) {
my $dirpath = '.' ; $dirpath = shift if @_ ; # OOPS!!!!!
my $types = 'A' ; $types = shift if @_ ;
my $wildcard = undef ; $wildcard = shift if @_ ;
my @filenames = ();
my @filerecords = ();
@filenames = <${wildcard}>; # OOPS!!!!!
if ( ! @filenames ) {
warn "Warning from GetFiles: fileglob returned no file names.\n";
}
# Iterate through names of files in current directory, collecting info on files:
FILE: foreach my $name (@filenames)
{
# Reject '.' and '..' to avoid infinite loops & infinite recursions, and because
# these are not actual directories, and because we don't want to list or count these:
next FILE if '.' eq $name || '..' eq $name;
# Set "is" variables to keep track of what kind of file this is:
my $is_regu = -f $name; # regular file
my $is_sdir = -d $name && ! -l $name; # non-link dir
my $is_link = -l $name && ! -d $name; # non-dir link
my $is_slkd = -d $name && -l $name; # SYMLINKD
# Filter files according to $types:
given ($types) {
when ('F') {next FILE unless $is_regu ;} # regular files
when ('D') {next FILE unless $is_sdir ;} # non-link dirs
when ('B') {next FILE unless $is_regu || $is_sdir;} # regular files & non-link dirs
when ('A') { ;} # All
default { ;} # All
}
# Get current file's info:
my ($dev, $inode, $mode, $nlink, $size, $atime, $mtime, $ctime)
= (stat($name))[0,1,2,3,7,8,9,10];
# Push file info record for this file onto array:
push @filerecords,
{
"Name" => $name,
"Dev" => $dev,
"Inode" => $inode,
"Mode" => $mode,
"Nlink" => $nlink,
"Size" => $size,
"Atime" => $atime,
"Mtime" => $mtime,
"Ctime" => $ctime
};
};
return \@filerecords;
}
Hmmm. I suddenly see 1 glaring bug in that re-write, but I'll
bring it up as a separate thread.
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
------------------------------
Date: Fri, 1 May 2015 05:36:26 -0700 (PDT)
From: mentificium@gmail.com
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <42ad02f3-d471-4fbd-9793-a7b7b6d99e5d@googlegroups.com>
On Thursday, April 30, 2015 at 7:04:54 PM UTC-7, Kaz Kylheku wrote:
> 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.
Each AI Mind is a large, sprawling program,
therefore there is no simple "detailed requirement."
However, let me say here that since Perl handles
Unicode and therefore most human languages, the
http://ai.neocities.org/AiSteps.html page
with its Perl AI coding invites Netizens
not only to code AI in any _programming_ language
but also in any _natural_ (i.e., human) language.
>
> >> - 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?
http://ai.neocities.org/AiMind.html just now in Transcript mode:
AiMind version 14apr13A on Fri May 1 05:20:14 PDT 2015
Robot: I HELP KIDS
Human:
Robot:
Human: sally is a woman
Robot: DOES SALLY HAVE CHILD
Human:
Robot: WHAT IS A SALLY
Human:
Robot: I AM PERSON
Human:
>
> What is a concrete example of the sort of thing that it can infer?
MindForth and Wotan and the JavaScript AiMind.html
already know that oftentimes "a woman has a child".
Thus all I had to input up above was
"sally is a woman" and the JavaScript AI
inferred from Sally being a woman that
perhaps Sally has a child, and the AskUser
module posed the question expecting
"yes" or "no" or "maybe" or no response:
"DOES SALLY HAVE CHILD"?
>
> >> what are the inputs and expected outputs?
> > The inputs will be simple Subject-Verb-Object
>
> Will be? Aren't now? So when?
When the Perl AI advances to the same level of
development as the Forth and JavaScript AI's,
then the inputs and outputs will be comparable.
>
> But there is code now which is claimed to be "AI".
http://www.nlg-wiki.org/systems/Mind.Forth in English
http://dl.acm.org/citation.cfm?doid=307824.307853
http://www.nlg-wiki.org/systems/Wotan in German
http://www.nlg-wiki.org/systems/Mind in English
http://www.nlg-wiki.org/systems/Dushka in Russian
>
> Can you give *conrete examples* (ASCII text) of inputs, and their
> expected outputs?
Just point Microsoft Internet Explorer at
http://ai.neocities.org/AiMind.html
as I did above and type in something like
"boys play games" and
"john is a boy".
>
> > 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.)
SVO is a simple subset of natural language -- for now.
>
> >> 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".
To me those terms are from mathematics; I do linguistics.
>
> The question means, how are you validating the correctness
> of the code, that it is working?
Thanks.
>
> If you make a change which introduces a bug (something stops working:
> regression), how will you know?
The output will not make sense.
>
> 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?
By the process of trial and error.
I have to go right now and start my day.
Thanks for the good questions.
Cheers,
Arthur T. Murray
------------------------------
Date: Fri, 01 May 2015 14:29:54 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Attn: Perl Newbies! Learn AI and Perl simultaneously
Message-Id: <Z9KdnZ_knadJ4t7InZ2dnUU78dOdnZ2d@giganews.com>
On 01/05/15 13:36, mentificium@gmail.com wrote:
> When the Perl AI advances to the same level of
> development as the Forth and JavaScript AI's,
> then the inputs and outputs will be comparable.
Nah; the APL one will be best. Or perhaps the FORTRAN one. When are
you going to try the PL/1 version? Maybe that will be better. But
avoid C++, you'd find the object modelling difficult.
Oh, wait; go look at LISP. That'll work.
--
Henry Law Manchester, England
------------------------------
Date: Fri, 01 May 2015 10:22:08 -0700
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Folding dirpath into wildcard for fileglob.
Message-Id: <1-udnbAoOcvcK97InZ2dnUVZ572dnZ2d@giganews.com>
Last night I wrote, in another thread:
> ... I ... re-wrote my "GetFiles" subroutine ...
>
> sub GetFiles (;$$$) {
> my $dirpath = '.' ; $dirpath = shift if @_ ; # OOPS!!!!!
> my $types = 'A' ; $types = shift if @_ ;
> my $wildcard = undef ; $wildcard = shift if @_ ;
> my @filenames = ();
> my @filerecords = ();
> @filenames = <${wildcard}>; # OOPS!!!!!
>
> ... etc ...
>
> }
>
> I suddenly see 1 glaring bug in that re-write, but I'll
> bring it up as a separate thread.
(Actually, 2 bugs: $wildcard should default to '*', not undef.)
The bug being that the sub now ignores $dirpath. To fix that,
I had to fold $dirpath into $wildcard. Not so easy, because
a fileglob wildcard can contain several wildcards separated by
spaces, such as:
.* *.abc *.xyz
So to fold $dirpath into $wildcard, I wrote:
sub GetFiles (;$$$) {
my $dirpath = '.' ; $dirpath = shift if @_ ;
my $types = 'A' ; $types = shift if @_ ;
my $wildcard = '*' ; $wildcard = shift if @_ ;
my @filenames = ();
my @filerecords = ();
my $cards = join ' ', map $dirpath . '/' . $_ , split / /, $wildcard;
@filenames = <${cards}>;
FILE: foreach my $name (@filenames) {
... push info on each file into @filerecords ...
}
return \@filerecords;
}
Which seems to work. Though, this line makes me queasy:
my $cards = join ' ', map $dirpath . '/' . $_ , split / /, $wildcard;
Is there a better way of doing that? Or is that about as clean
as one can get it?
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley
------------------------------
Date: Fri, 01 May 2015 19:03:40 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <87bni4tbsz.fsf@doppelsaurus.mobileactivedefense.com>
Robbie Hatley <see.my.sig@for.my.address> writes:
[...]
> sub GetFiles (;$$$) {
> my $dirpath = '.' ; $dirpath = shift if @_ ;
> my $types = 'A' ; $types = shift if @_ ;
> my $wildcard = '*' ; $wildcard = shift if @_ ;
> my @filenames = ();
> my @filerecords = ();
>
> my $cards = join ' ', map $dirpath . '/' . $_ , split / /, $wildcard;
[...]
> Is there a better way of doing that? Or is that about as clean
> as one can get it?
Alternate way:
$cards = $wildcard;
$cards =~ s/(\S+)/$dirpath\/$1/g;
------------------------------
Date: Fri, 01 May 2015 23:18:38 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi0n3h$op8$1@news.grnet.gr>
On 1/5/2015 20:22, Robbie Hatley wrote:
> Last night I wrote, in another thread:
I suspect you want the following
#!/usr/bin/perl
use strict;
use warnings;
my $files = GetFiles('/tmp', '*.???');
sub GetFiles
{
my $dir = exists $_[0] ? $_[0] : '.';
my $mask = exists $_[1] ? $_[1] : '*';
my $result;
unless (-d $dir) {warn "Directory \"$dir\" does not exist\n"; return []}
opendir DIR, $dir or eval {warn "Could not read directory $dir\n";
return []};
$mask =~s/([^?*]+)/\Q$1\E/g;
$mask =~s|\?|.|g;
$mask =~s|\*+|.*?|g;
$mask = qr/^$mask$/i;
while (readdir DIR){
next unless -f "$dir/$_";
next unless $_=~$mask;
push @{$result},$_}
closedir DIR;
$result
}
------------------------------
Date: Fri, 01 May 2015 16:54:17 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi13lg$f38$1@dont-email.me>
On 5/1/2015 10:22, Robbie Hatley wrote:
>
> sub GetFiles (;$$$) {
> my $dirpath = '.' ; $dirpath = shift if @_ ;
> my $types = 'A' ; $types = shift if @_ ;
> my $wildcard = '*' ; $wildcard = shift if @_ ;
> my @filenames = ();
> my @filerecords = ();
Just a style note - I normally write code like that like this:
my $dirpath = shift || '.';
my $types = shift || 'A';
my $wildcard = shift || '*';
------------------------------
Date: Sat, 02 May 2015 15:05:13 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <87oam3vzvq.fsf@doppelsaurus.mobileactivedefense.com>
"$Bill" <news@todbe.com> writes:
> On 5/1/2015 10:22, Robbie Hatley wrote:
>> sub GetFiles (;$$$) {
>> my $dirpath = '.' ; $dirpath = shift if @_ ;
>> my $types = 'A' ; $types = shift if @_ ;
>> my $wildcard = '*' ; $wildcard = shift if @_ ;
>> my @filenames = ();
>> my @filerecords = ();
>
> Just a style note - I normally write code like that like this:
>
> my $dirpath = shift || '.';
> my $types = shift || 'A';
> my $wildcard = shift || '*';
Robbie's code uses an argument if one was passed as it checks the length
of the argument vector. Your code will overwrite a passed argument if
its value is considered false, ie, if it's undef, an emtpy string, or
zero(!).
--------
sub subr
{
my $a = shift || 'no argument';
print("'$a'\n");
}
subr(0.0);
--------
The last two cases can be avoided by using // instead of ||.
------------------------------
Date: Sat, 02 May 2015 08:34:57 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi2qp8$hpf$1@dont-email.me>
On 5/2/2015 07:05, Rainer Weikusat wrote:
> "$Bill" <news@todbe.com> writes:
>> On 5/1/2015 10:22, Robbie Hatley wrote:
>>> sub GetFiles (;$$$) {
>>> my $dirpath = '.' ; $dirpath = shift if @_ ;
>>> my $types = 'A' ; $types = shift if @_ ;
>>> my $wildcard = '*' ; $wildcard = shift if @_ ;
>>> my @filenames = ();
>>> my @filerecords = ();
>>
>> Just a style note - I normally write code like that like this:
>>
>> my $dirpath = shift || '.';
>> my $types = shift || 'A';
>> my $wildcard = shift || '*';
>
> Robbie's code uses an argument if one was passed as it checks the length
> of the argument vector. Your code will overwrite a passed argument if
> its value is considered false, ie, if it's undef, an emtpy string, or
> zero(!).
Which works fine for me. If I wanted to allow those possibilities, I'd
have done the shift and then checked for them and handled it.
------------------------------
Date: Sat, 02 May 2015 17:16:43 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <87a8xnnedw.fsf@doppelsaurus.mobileactivedefense.com>
"$Bill" <news@todbe.com> writes:
> On 5/2/2015 07:05, Rainer Weikusat wrote:
>> "$Bill" <news@todbe.com> writes:
>>> On 5/1/2015 10:22, Robbie Hatley wrote:
>>>> sub GetFiles (;$$$) {
>>>> my $dirpath = '.' ; $dirpath = shift if @_ ;
>>>> my $types = 'A' ; $types = shift if @_ ;
>>>> my $wildcard = '*' ; $wildcard = shift if @_ ;
>>>> my @filenames = ();
>>>> my @filerecords = ();
>>>
>>> Just a style note - I normally write code like that like this:
>>>
>>> my $dirpath = shift || '.';
>>> my $types = shift || 'A';
>>> my $wildcard = shift || '*';
>>
>> Robbie's code uses an argument if one was passed as it checks the length
>> of the argument vector. Your code will overwrite a passed argument if
>> its value is considered false, ie, if it's undef, an emtpy string, or
>> zero(!).
>
> Which works fine for me.
Your leading statement suggested you considered both variants to be
functionally identical. But they aren't.
------------------------------
Date: Sat, 02 May 2015 21:05:27 +0200
From: gamo <gamo@telecable.es>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi375o$a3g$1@speranza.aioe.org>
El 02/05/15 a las 18:16, Rainer Weikusat escribió:
>>>> Just a style note - I normally write code like that like this:
>>>> >>>
>>>> >>> my $dirpath = shift || '.';
>>>> >>> my $types = shift || 'A';
>>>> >>> my $wildcard = shift || '*';
>>> >>
>>> >>Robbie's code uses an argument if one was passed as it checks the length
>>> >>of the argument vector. Your code will overwrite a passed argument if
>>> >>its value is considered false, ie, if it's undef, an emtpy string, or
>>> >>zero(!).
>> >
>> >Which works fine for me.
> Your leading statement suggested you considered both variants to be
> functionally identical. But they aren't.
What's wrong with new syntax?
my $dirpath = shift // '.';
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Sat, 02 May 2015 13:32:17 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi3c6o$q9p$1@dont-email.me>
On 5/2/2015 12:05, gamo wrote:
> El 02/05/15 a las 18:16, Rainer Weikusat escribió:
>>>>> Just a style note - I normally write code like that like this:
>>>>> >>>
>>>>> >>> my $dirpath = shift || '.';
>>>>> >>> my $types = shift || 'A';
>>>>> >>> my $wildcard = shift || '*';
>>>> >>
>>>> >>Robbie's code uses an argument if one was passed as it checks the length
>>>> >>of the argument vector. Your code will overwrite a passed argument if
>>>> >>its value is considered false, ie, if it's undef, an emtpy string, or
>>>> >>zero(!).
>>> >
>>> >Which works fine for me.
>> Your leading statement suggested you considered both variants to be
>> functionally identical. But they aren't.
>
> What's wrong with new syntax?
>
> my $dirpath = shift // '.';
How does that work with Rainer's test code: subr(0.0);
------------------------------
Date: Sat, 02 May 2015 23:03:40 +0200
From: gamo <gamo@telecable.es>
Subject: Re: Folding dirpath into wildcard for fileglob.
Message-Id: <mi3e3d$t44$1@speranza.aioe.org>
El 02/05/15 a las 22:32, $Bill escribió:
> On 5/2/2015 12:05, gamo wrote:
>> El 02/05/15 a las 18:16, Rainer Weikusat escribió:
>>>>>> Just a style note - I normally write code like that like this:
>>>>>> >>>
>>>>>> >>> my $dirpath = shift || '.';
>>>>>> >>> my $types = shift || 'A';
>>>>>> >>> my $wildcard = shift || '*';
>>>>> >>
>>>>> >>Robbie's code uses an argument if one was passed as it checks the
>>>>> length
>>>>> >>of the argument vector. Your code will overwrite a passed
>>>>> argument if
>>>>> >>its value is considered false, ie, if it's undef, an emtpy
>>>>> string, or
>>>>> >>zero(!).
>>>> >
>>>> >Which works fine for me.
>>> Your leading statement suggested you considered both variants to be
>>> functionally identical. But they aren't.
>>
>> What's wrong with new syntax?
>>
>> my $dirpath = shift // '.';
>
> How does that work with Rainer's test code: subr(0.0);
I think that good:
$ perl test.def
0
$ cat test.def
#!/usr/bin/perl -w
print subsr(0.0),"\n";
sub subsr{
return shift // '.';
}
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Fri, 01 May 2015 11:40:42 +0200
From: gamo <gamo@telecable.es>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <mhvhmq$fk8$1@speranza.aioe.org>
El 28/04/15 a las 10:54, Martijn Lievaart escribió:
> 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.
>
> M4
>
Functionally equivalent if $_ is string of only one character.
But if you want to discuss for the pleasure of discussing...
Do you want speed tests?
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Fri, 01 May 2015 18:39:23 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How do I use "when" to check for "one of two options"?
Message-Id: <87mw1otcxg.fsf@doppelsaurus.mobileactivedefense.com>
gamo <gamo@telecable.es> writes:
> El 28/04/15 a las 10:54, Martijn Lievaart escribió:
>> 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.
>
> Functionally equivalent if $_ is string of only one character.
This is something which probably happened to be true for the original
example but it isn't necessarily true for other conceivable uses of
given/ when.
---------------
use feature 'switch';
sub finde_affen
{
given (lc($_[0])) {
when ('affe') {
print("Es ist ein Affe!\n");
}
default {
print("Ein $_ ist kein Affe.\n");
}
}
}
sub finde_affe
{
given ($_[0]) {
when (/affe/i) {
print("Ist ein $_ ein Affe?\n");
}
default {
print("Ein $_ ist kein Affe.\n");
}
}
}
my @dingsbumse = qw(affe Kamel Nashorn Affe Affenbrotbaum Zahnstocherzerspanungsmachine affenzahn);
finde_affen($_) for @dingsbumse;
print("\n");
finde_affe($_) for @dingsbumse;
------------
As to the more general given/when problem: It's sometimes sensible to
avoid reinventing the square wheel over and over again by looking at
'how other people do it' instead of experimenting wildly. Multiway
conditionals are by no way a new invention, rather a standard feature of
higher-level programming languages pretty much since they came into
being.
According to a quick, informal survy, LISP had some sort of
multiway conditional since ever in the form of cond. More restricted
constructs more similar to non-LISP mulitways appeared in InterLISP and
MacLISP (caseq/ selectq). Algol 68 had a multiway conditional but I
wasn't able to determine its intended semantics (or even syntax) within
a reasonable amount of time from the Algol 68 language report[*]. COBOL
gained support for multiway conditionals with COBOL 85. All of these are
fairly alien when seen in the context of Perl.
Considering more closely related languages, C had switch since its
conception (and Pascal case). The "programming language simulated by the
cfront preprocessor" obviously shares all good things with C. Java has a
switch statement. I'm purposely ignoring PHP.
This incomplete list should be sufficient to demonstrate that this is
not some "dubious new concept" while people with properly working (or
"properly restricted") brains have always been contempt with if - then -
else cascades.
As to the properties, in C, the controlling expression of a switch
statements has to be of integer type. case-labels must use compile-time
constants. There's no syntax for ranges or sets of values but more than
one case label may be attached to the same block.
The Pascal case supports ordinal types, enumerated types, chars and (as
an extension) strings for case cases which must be constants. Ranges or
sets of values are also supported.
The Java switch used to support integer or enum types for 'case cases',
meanwhile, it also supports strings. They must be compile-time
constants. Ranges or sets are not supported but - similar to C - more
than one case may be attached to a statement block.
The common denominator of all of these (which are actually used in
practice instead of being considered experiments) is that there's some
kind of controlling expression which has to evualuate to something which
can be compared for equality using built-in language features and that
it is compared with a disjunct set of constant expressions. Comparing
with a set of constants for a single case is always supported, only
Pascal provides the additional syntactic sugar of supporting range
notation for such sets.
This would provide a suitable, basic set of features for a
non-experimental multiway conditional which could then be extended as
consensus on sensible extensions is reached, as opposed to the
"everything we can think of pushed into it upfront somehow plus a couple
of kitchen sinks to be on the safe side" approach behind 'smart
matching'.
Possibly offensive (and possibly non-funny) joke below:
[*] In order to emphasize the proud legacy of languages which don't
exist because of their specification, of the committee-me-harder
organization necessary to create such a specification, of the throw out the
baby to distill the bathwater approach taken by such committees and -
last but not least - to hint at the fact that - ultimatively - the thing
has to be unplugged for the good of mankind in case it refuses to accept
its own fallibillity, we hereby announce that the language erronously
referred to as 'Perl 6' shall be known as ALGOL 2001 everhereafter.
------------------------------
Date: Fri, 01 May 2015 19:26:05 -0500
From: scorpionjs <scorpionjs@yahoo.com>
Subject: Re: How to "unuse" Perl modules
Message-Id: <neCdnXk8a7IAhNnInZ2dnUU7-I2dnZ2d@giganews.com>
Create a shell of your main script. Remove the event loop and where you would normally require the user's script, put "eval ($ENV{USER_SCRIPT});".
From your main script where you would normally do the eval, instead do $ENV{USER_SCRIPT} = "user_script"; and then do a sysem call on your shell of a script.
And don't complain about being 10 years to late, I was looking to see if there was a solution for another problem I'm having.
------------------------------
Date: Sat, 02 May 2015 11:39:32 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: How to "unuse" Perl modules
Message-Id: <mi22g5$1di$1@news.grnet.gr>
On 2/5/2015 03:26, scorpionjs wrote:
no modulename
------------------------------
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 4425
***************************************