[28112] in Perl-Users-Digest
Perl-Users Digest, Issue: 9476 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 15 18:06:54 2006
Date: Sat, 15 Jul 2006 15:05:04 -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, 15 Jul 2006 Volume: 10 Number: 9476
Today's topics:
Re: finding perl info on google can be hard ilikesluts@gmail.com
How get UTF-8 from urlencoded web form <ynleder@nspark.org>
Re: How get UTF-8 from urlencoded web form <noreply@gunnar.cc>
Re: How get UTF-8 from urlencoded web form <ynleder@nspark.org>
Re: How get UTF-8 from urlencoded web form <noreply@gunnar.cc>
Re: how match/expose the value in an empty variable hav <jack_posemsky@yahoo.com>
Re: how match/expose the value in an empty variable hav <tadmc@augustmail.com>
how to get the caller's information? <chenchp@gmail.com>
Re: how to get the caller's information? <DJStunks@gmail.com>
Re: how to get the caller's information? <brian.d.foy@gmail.com>
Re: Interfacing with Matlab using Win32::OLE <1usa@llenroc.ude.invalid>
Problem with ([\w ]+?) <poubelles@gmail.com>
Re: Problem with ([\w ]+?) <1usa@llenroc.ude.invalid>
Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
Re: Requirements for Perl on Windows XP? <sigzero@gmail.com>
Re: Requirements for Perl on Windows XP? <1usa@llenroc.ude.invalid>
Re: Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
Re: Requirements for Perl on Windows XP? <1usa@llenroc.ude.invalid>
Re: Traverse a directory <weberw@adelphia.net>
Re: Traverse a directory <weberw@adelphia.net>
Re: What is a type error? <cfc@shell01.TheWorld.com>
Re: What is a type error? <marshall.spight@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Jul 2006 02:01:50 -0700
From: ilikesluts@gmail.com
Subject: Re: finding perl info on google can be hard
Message-Id: <1152954110.619292.112740@m79g2000cwm.googlegroups.com>
Hi Jue,
I was making an obersvation and bringing forward a talking point. I
thought that was obvious by the way I posted an observation. I'll
consider being more clear next time.
I'm not the type of person who needs to pass judgment on everything
that passes across my conciousness. Some things just are.
> Fine. As you have discovered yourself and I think nobody will disagree
> Google is not a good tool to find information about Perl. So? In which way
> do you suggest to change Perl to make it easier to find information about
> Perl in Google?
>
> jue
------------------------------
Date: Sat, 15 Jul 2006 18:43:45 +0200
From: Yohan N. Leder <ynleder@nspark.org>
Subject: How get UTF-8 from urlencoded web form
Message-Id: <MPG.1f2339abb4343fb798988a@news.tiscali.fr>
Hello.
All my tests are done using ActivePerl 5.8.8.817 under Win2K FR and
Apache2.
I'm trying to obtain (and display) user data which come from a web form
with enctype as 'application/x-www-form-urlencoded' and don't succeed. I
can do-it if the form is a 'multipart/form-data' but not a
'application/x-www-form-urlencoded'.
Here is a script to show the difference :
---- BEGIN ----
#!/usr/bin/perl -w
my $this = "utf8_and_webform.pl";
require 5.8.0;
use utf8;
binmode(STDOUT, ':utf8');
print "Content-type: text/html; charset=UTF-8\n\n";
if (defined $ENV{'QUERY_STRING'} && length($ENV{'QUERY_STRING'}) > 0)
{&see;}
else {&ask;}
exit 0;
sub ask
{ # provide web forms for user to enter data
print <<PAGE
<html><head><title>Test about UTF-8 and web form</title></head><body>
Use the form you want and see the resulting data.
<p>
FORM with enctype as 'application/x-www-form-urlencoded' :<br>
<form action='$this?x' method='post' accept-charset='UTF-8'
enctype='application/x-www-form-urlencoded'>
<textarea name='msg' rows='4' cols='30' wrap='virtual'></textarea>
<input type='submit' value='send'>
</form></body></html></p>
<p>
FORM with enctype as 'multipart/form-data' :<br>
<form action='$this?x' method='post' accept-charset='UTF-8'
enctype='multipart/form-data'>
<textarea name='msg' rows='4' cols='30' wrap='virtual'></textarea>
<input type='submit' value='send'></p>
</form></body></html>
PAGE
> [quoted text muted]
}
sub see
{ # display data which come from user form
my $data='';
binmode(STDIN, ':utf8'); # or ':encoding('UTF-8')'
read(STDIN, $data, $ENV{'CONTENT_LENGTH'});
# OR
#use Encode qw(decode);
#read(STDIN, $data, $ENV{'CONTENT_LENGTH'});
#$data = decode('UTF-8', $data);
print $data;
> [quoted text muted]
}
----- END ----
For example, if I submit the 'urlencoded' form (the first one, at top of
generated web page, if you run the script without any url parameter)
with the letter 'é' (accentuated e) inside the textarea, I get 'msg=%C3%
A9' displayed in the browser (knowing this has been proceeded through
the see() sub).
While, if I submit the same 'é' from the 'multipart/form-data' form (the
second one, at bottom of generated web page), I get a well interpreted
UTF-8 'é' as expected.
How to get this same UTF-8 'é' when form uses 'application/x-www-form-
urlencoded' enctype ? How to modify the see() sub for this urlencoded
form case ?
------------------------------
Date: Sat, 15 Jul 2006 20:18:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <4hsptuF13iu2U1@individual.net>
Yohan N. Leder wrote:
> if I submit the 'urlencoded' form (the first one, at top of
> generated web page, if you run the script without any url parameter)
> with the letter 'é' (accentuated e) inside the textarea, I get 'msg=%C3%
> A9' displayed in the browser (knowing this has been proceeded through
> the see() sub).
>
> While, if I submit the same 'é' from the 'multipart/form-data' form (the
> second one, at bottom of generated web page), I get a well interpreted
> UTF-8 'é' as expected.
>
> How to get this same UTF-8 'é' when form uses 'application/x-www-form-
> urlencoded' enctype ?
The problem is covered by this FAQ entry:
http://faq.perl.org/perlfaq9.html#How_do_I_decode_a_CG
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 15 Jul 2006 23:07:54 +0200
From: Yohan N. Leder <ynleder@nspark.org>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <MPG.1f237794b3db70a198988b@news.tiscali.fr>
In article <4hsptuF13iu2U1@individual.net>, noreply@gunnar.cc says...
> The problem is covered by this FAQ entry:
> http://faq.perl.org/perlfaq9.html#How_do_I_decode_a_CG
>
It doesn't explain the problem, but remove the problem using CGI.pm, and
I would like to understand the problem.
------------------------------
Date: Sat, 15 Jul 2006 23:51:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <4ht6euF16u6mU1@individual.net>
Yohan N. Leder wrote:
> In article <4hsptuF13iu2U1@individual.net>, noreply@gunnar.cc says...
>>The problem is covered by this FAQ entry:
>>http://faq.perl.org/perlfaq9.html#How_do_I_decode_a_CG
>
> It doesn't explain the problem, but remove the problem using CGI.pm, and
> I would like to understand the problem.
Excellent learning approach.
The browser automatically URI escapes 'unsafe' characters when you make
a GET or an x-www-form-urlencoded POST request. Hence those characters
need to be unescaped by the web server. CGI.pm as well as other modules
for parsing CGI data takes care of that.
You can study the docs for the Perl module URI::Escape for a better
explanation.
I suppose you should also read up on the HTTP protocol.
HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 15 Jul 2006 00:43:00 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: Re: how match/expose the value in an empty variable having length of 1
Message-Id: <1152949380.123714.64060@p79g2000cwp.googlegroups.com>
Jack wrote:
> Hi folks,
>
> Ok I am stumped... I am reading a fileline in as follows:
>
> 12535957@140@2006-07-08 09:34:45.000@@@2005-11-24@
>
> and splitting on the "@"...
> open(SOURCE1,$filename1)
> @columnarray = split(/\@/, $_);
>
> Whats really wierd is $columnarray[4] has a length of 1, when clearly
> above its NULL !!
> I want to be able to recognize this as null, but you cant even match
> regex it... I tried
>
> if ($columnarray[4] =~ m/.*?[[:print:]]/) { print " NON PRINTABLE
> "."\n"; }
> $columnarray[4] =~ s/^\s+//;
> $columnarray[4] =~ s/\s+$//;
> $length = length @columnarray[4]."\n";
> and a number of other things that dont work.. how do I identify "WHAT"
> is making up the length =1 ?
>
> Also, what is the detection match test for NULL ?
>
> Thank you all much,
> Jack
NEVERMIND.. sorry.. I figured it out.. no need to post.
------------------------------
Date: Sat, 15 Jul 2006 07:44:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: how match/expose the value in an empty variable having length of 1
Message-Id: <slrnebhopl.62u.tadmc@magna.augustmail.com>
Jack <jack_posemsky@yahoo.com> wrote:
> $length = length @columnarray[4]."\n";
^^
^^ this is one character long
And you should always enable warnings when developing Perl code.
> how do I identify "WHAT"
> is making up the length =1 ?
By looking closely at the string above that is the argument for length().
> Also, what is the detection match test for NULL ?
Perl does not have anything known as NULL. I expect you mean
an "empty string".
print "empty string\n" unless length $columnarray[4];
or
print "empty string\n" if $columnarray[4] =~ /^\z/;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Jul 2006 05:28:42 -0700
From: "Brady" <chenchp@gmail.com>
Subject: how to get the caller's information?
Message-Id: <1152966522.657239.178120@s13g2000cwa.googlegroups.com>
hi, all,
i want to have a sub debug, which takes a string as a parameter, and
print the file name and line number of the place invoking the sub.
I tried to :
in main.pl:
if ($something_is_wrong) {
Mylib::Debug("wrong!!!");
}
in Mylib.pm
sub Debug()
{
print STDERR, "__FILE__:__LINE__", @_;
}
but, the __FILE__ and __LINE__ is the Mylib.pm and the line number of
Mylib.pm.
how to get the caller's place?
thanks & best wishes!
/Brady
------------------------------
Date: 15 Jul 2006 06:03:56 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: how to get the caller's information?
Message-Id: <1152968636.726975.40180@b28g2000cwb.googlegroups.com>
Brady wrote:
> hi, all,
>
> i want to have a sub debug, which takes a string as a parameter, and
> print the file name and line number of the place invoking the sub.
>
> I tried to :
> in main.pl:
>
> if ($something_is_wrong) {
> Mylib::Debug("wrong!!!");
> }
>
> in Mylib.pm
>
> sub Debug()
> {
> print STDERR, "__FILE__:__LINE__", @_;
> }
>
> but, the __FILE__ and __LINE__ is the Mylib.pm and the line number of
> Mylib.pm.
>
> how to get the caller's place?
use Carp;
-jp
------------------------------
Date: Sat, 15 Jul 2006 08:49:52 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: how to get the caller's information?
Message-Id: <150720060849527432%brian.d.foy@gmail.com>
In article <1152966522.657239.178120@s13g2000cwa.googlegroups.com>,
Brady <chenchp@gmail.com> wrote:
> how to get the caller's place?
have you tried the caller() builtin?
perldoc -f caller
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Sat, 15 Jul 2006 14:08:00 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Interfacing with Matlab using Win32::OLE
Message-Id: <Xns9801672D88A60asu1cornelledu@127.0.0.1>
Ben Morrow <benmorrow@tiscali.co.uk> wrote in
news:4bemo3-b8v.ln1@osiris.mauzo.dyndns.org:
> Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
...
>> Now, this opens some possibilities.
>
> Err... I don't think so.
<Various good points snipped for brevity>
It looks like I misread the documentation.
Thank you once more more for the correction.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 15 Jul 2006 14:42:48 -0700
From: "forwax" <poubelles@gmail.com>
Subject: Problem with ([\w ]+?)
Message-Id: <1152999768.027653.88390@m79g2000cwm.googlegroups.com>
Hi there,
I'm trying to use "([\w ]+?)" to get some city name and is team name
out in some kind of condition but seems not to work with 3 city/team
that I got. The code that I use is at the bottom of the post.
Here some that work:
- "Edmonton Oilers"
- "Detroit Red Wings"
- "Montreal Canadiens"
But it doesn't work with does 3:
- "St.Louis Blues"
- "Wilkes-Barre/Scranton Penguins"
- "Omaha Ak-Sar-Ben Knights"
Should "([\w ]+?)" be enough to work or I'm missing something ?
Here the code from 2 different condition:
1.
elsif ($_ =~ /<tr><td class="STHSSchedule_GameNumber">\d+<\/td><td
class="STHSSchedule_ProLink"><a href="$prefix-(\d+).html">([\w ]+?)
\((\d+)\) vs ([\w ]+?) \((\d+)\)<\/a>(.*)<\/td><td
class="STHSSchedule_FarmLink">/i) { }
2.
elsif ($_ =~ /<a href="$prefix-Farm-(\d+).html">([\w ]+?) \((\d+)\) vs
([\w ]+?) \((\d+)\)(<\/a>)(.*)<\/td><\/tr>/i) { }
------------------------------
Date: Sat, 15 Jul 2006 21:49:11 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <Xns9801B55E65ABDasu1cornelledu@127.0.0.1>
"forwax" <poubelles@gmail.com> wrote in news:1152999768.027653.88390
@m79g2000cwm.googlegroups.com:
> I'm trying to use "([\w ]+?)"
...
> But it doesn't work with does 3:
> - "St.Louis Blues"
> - "Wilkes-Barre/Scranton Penguins"
> - "Omaha Ak-Sar-Ben Knights"
>
> Should "([\w ]+?)" be enough to work or I'm missing something ?
perldoc perlre
In addition, Perl defines the following:
\w Match a "word" character (alphanumeric plus "_")
> 1.
> elsif ($_ =~ /<tr><td class="STHSSchedule_GameNumber">\d+<\/td><td
> class="STHSSchedule_ProLink"><a href="$prefix-(\d+).html">([\w ]+?)
> \((\d+)\) vs ([\w ]+?) \((\d+)\)<\/a>(.*)<\/td><td
> class="STHSSchedule_FarmLink">/i) { }
>
> 2.
> elsif ($_ =~ /<a href="$prefix-Farm-(\d+).html">([\w ]+?) \((\d+)\) vs
> ([\w ]+?) \((\d+)\)(<\/a>)(.*)<\/td><\/tr>/i) { }
This is impossible to read and very error prone. You would do yourself a
service by properly parsing HTML:
perldoc -q html
http://search.cpan.org/~gaas/HTML-Parser-3.55/
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 15 Jul 2006 02:04:44 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Requirements for Perl on Windows XP?
Message-Id: <1152954284.047334.179590@b28g2000cwb.googlegroups.com>
What are the requirements for running a Perl script on Windows XP Pro
(tablet edition)?
I am trying to run a command-line utility, "UTIL", on my tablet PC
running WinXP-SP2. UTIL was written in Perl, so I installed ActivePerl
5.8.8.817 from ActiveState.com. UTIL also requires a couple of CPAN
modules which I installed by using "nmake", which is "make" for Win32.
Reading about error messages I got trying to run UTIL caused me to
install "Visual C++ 2005 Express" and "Microsoft Platform SDK for
Windows Server 2003 R2," but now I am tangled up in DLL Hell, unmanaged
assemblies, manifests (I think). The ugly details are here:
http://groups.google.com/group/microsoft.public.windowsxp.general/bro...
There must be an easier way to get the C stuff I need to support a Perl
application!
Your help is appreciated!
Teffy
------------------------------
Date: 15 Jul 2006 04:18:01 -0700
From: "Robert Hicks" <sigzero@gmail.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1152962281.578274.159350@m73g2000cwd.googlegroups.com>
Teffy wrote:
> What are the requirements for running a Perl script on Windows XP Pro
> (tablet edition)?
>
> I am trying to run a command-line utility, "UTIL", on my tablet PC
> running WinXP-SP2. UTIL was written in Perl, so I installed ActivePerl
> 5.8.8.817 from ActiveState.com. UTIL also requires a couple of CPAN
> modules which I installed by using "nmake", which is "make" for Win32.
>
> Reading about error messages I got trying to run UTIL caused me to
> install "Visual C++ 2005 Express" and "Microsoft Platform SDK for
> Windows Server 2003 R2," but now I am tangled up in DLL Hell, unmanaged
> assemblies, manifests (I think). The ugly details are here:
>
> http://groups.google.com/group/microsoft.public.windowsxp.general/bro...
>
> There must be an easier way to get the C stuff I need to support a Perl
> application!
>
> Your help is appreciated!
>
> Teffy
What modules are required to run UTIL?
Robert
------------------------------
Date: Sat, 15 Jul 2006 14:02:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <Xns9801665123D63asu1cornelledu@127.0.0.1>
"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in
news:1152954284.047334.179590@b28g2000cwb.googlegroups.com:
> 5.8.8.817 from ActiveState.com. UTIL also requires a couple of CPAN
> modules which I installed by using "nmake", which is "make" for Win32.
Start Menu
-> Programs
-> ActivePerl 5.8.8 Build 817
-> Perl Package Manager
See if the modules exist in pre--compiled form.
> http://groups.google.com/group/microsoft.public.windowsxp.general/bro...
This URL does not lead anywhere.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 15 Jul 2006 14:55:14 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1153000514.486700.109830@h48g2000cwc.googlegroups.com>
HTML::LinkExtor
(http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
SOAP::Lite (http://search.cpan.org/dist/SOAP-Lite/) are required by
UTIL.
Robert Hicks wrote:
>
> What modules are required to run UTIL?
>
> Robert
------------------------------
Date: Sat, 15 Jul 2006 22:00:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <Xns9801B7442E6FEasu1cornelledu@127.0.0.1>
"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in
news:1153000514.486700.109830@h48g2000cwc.googlegroups.com:
[ Please don't top-post. Please do read the posting guidelines for
this group.
]
> Robert Hicks wrote:
>>
>> What modules are required to run UTIL?
>
> HTML::LinkExtor
> (http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
> SOAP::Lite (http://search.cpan.org/dist/SOAP-Lite/) are required by
> UTIL.
And, what happened when you tried to install them using PPM?
Start Menu
-> Programs
-> ActivePerl 5.8.8 Build 817
-> Perl Package Manager
Go ahead, feel free to read the documentation installed on your computer
in the same start menu folder, or just type:
perldoc PPM
on the command prompt.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 15 Jul 2006 09:10:33 -0700
From: "weberw@adelphia.net" <weberw@adelphia.net>
Subject: Re: Traverse a directory
Message-Id: <1152979833.211023.113620@35g2000cwc.googlegroups.com>
Tad- return if $File::Find::name =~ /folder 3/ gave the same results.
It excluded the folder but did include the contents. Also, does anyone
know how to print it so the out put would be formated like shown below?
The file name needs to print out at the end of the direcotry name.
Directory name1
file1.xls
file2.xls
Directory name2
file3.xls
file4.xls
file5.xls
------------------------------
Date: 15 Jul 2006 09:10:55 -0700
From: "weberw@adelphia.net" <weberw@adelphia.net>
Subject: Re: Traverse a directory
Message-Id: <1152979855.467317.179810@i42g2000cwa.googlegroups.com>
Tad McClellan wrote:
> weberw@adelphia.net <weberw@adelphia.net> wrote:
> > Tad- return if /folder 3/; still included the files inside the
> > folder 3 so it didn't work. It did exclude folder 3 but the contents
> > of folder 3 were displayed.
>
>
> return if $File::Find::name =~ /folder 3/;
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: 15 Jul 2006 15:52:30 -0400
From: Chris F Clark <cfc@shell01.TheWorld.com>
Subject: Re: What is a type error?
Message-Id: <sdd8xmuzlvl.fsf@shell01.TheWorld.com>
Joachim Durchholz wrote:
>
> You can have aliasing without pointers; e.g. arrays are fully sufficient.
> If i = j, then a [i] and a [j] are aliases of the same object.
"Marshall" <marshall.spight@gmail.com> writes:
> I am having a hard time with this very broad definition of aliasing.
> Would we also say that a[1+1] and a[2] are aliases? It seems
> to me, above, that we have only a, and with only one variable
> there can be no aliasing.
As you can see from the replies, all these things which you do not
consider aliasing are considered aliasing (by most everyone else, in
fact these are exactly what is meant by aliasing). There is good
reason for this. Let us explain this by looking again at the SQL
example that has been kicked around some.
>> SELECT * FROM persons WHERE name = "John"
>> and
>> SELECT * FROM persons WHERE surname = "Doe"
Some set of records are shared by both select clauses. Those records
are the aliased records. If the set is empty there is no problem. If
we do not update the records from one of the select clauses, we also
have no problem. However, if we update the records for one of the
select clauses and the set of aliased records is not empty, the
records returned by the other select clause have changed. Therefore,
everything we knew to be true about the "other" select clause may or
may not still be true. It's the may not case we are worried about.
For example, in the "imperative Mi-5" Q asks Moneypenny to run the
first query (name = John) to get a list of agents for infiltrating
Spectre. In another department, they're doing sexual reassignments
and updating the database with the second query (surname = Doe) and
making the name become Jane (along with other changes to make the
transformation correct). So, when Q select "John Doe" from the first
list and sends that agent on a mission Q is really sending "Jane Doe"
and Spectre realizes that the agent is one and kills her. Not a happy
result.
In the "functional Mi-5", the sexual reassignment group, makes clones
of the agents reassigned, so that there is now both a "John Doe" and a
"Jane Doe". Of course, the payroll is a little more bloated, so that
when Q says "John Doe" isn't needed for any further assignments, the
"Garbage Collection" department does a reduction in force and gets rid
of "John Doe". The good news is that they didn't send Jane Doe to her
death.
The problem with aliasing, we want the things we knew true in one part
of our program, i.e. the Johns on Q's list are still Johns and not
Janes, to be true after we've run another part of our program. If the
second part of our program can change what was true after the first
part of our program, we can't depend on the results from the first
part of our program, i.e. Q can send Jane Doe into certain death.
The problem is compounded by the complexities of our programs. When Q
selected his list, he didn't know of the department doing the
reassignments (and couldn't know because they were part of a
top-secret project). So, since bureaucracies grow to meet the
increasing needs of the bureaucracy, often the solution is increased
complexity, more regulations and paperwork to fill out, semaphores and
locks to hold on critical data, read-only data, status requests, etc.
All to keep Q from killing Jane by accident. Sometimes they work. the
reassignment department has to wait 30-days for the clearance to
perform their operation in which time John Doe completes the
infiltration of Spectre saves the world from destruction and is ready
for his next assignment.
The key point is that each record (and even each field in each record)
if it can be known by two names, is an alias. It is not sufficient to
talk about "whole" variables as not being aliased if there is some way
to refer to some part of the variable and change that part of the
variable. Thus, a[1+1] is an alias for a[2] if you can have one part
of the code talking about one and another part of the code talking
about the other.
To put it one still final way, consider the following code;
assert(sorted(array a));
a[1] = 2;
assert(sorted(array a)); // is this still true?
Because a[1] is an alias of array a, you cannot be certain that the
2nd assert will not fire (fail) without additional analysis.
assert(sorted(array a));
assert(a[0] <= 2);
assert(2 <= a[2]);
a[1] = 2;
assert(sorted(array a)); // this is still true!
-Chris
------------------------------
Date: 15 Jul 2006 13:56:18 -0700
From: "Marshall" <marshall.spight@gmail.com>
Subject: Re: What is a type error?
Message-Id: <1152996978.533372.223000@b28g2000cwb.googlegroups.com>
Joachim Durchholz wrote:
> Marshall schrieb:
>
> >> In some cases, you need an additional level of conceptual indirection -
> >> instead of *doing* the updates, you write a function that *describes* them.
> >
> > But then what do you do with that function?
>
> I pass it to an engine that's imperative.
>
> However, that engine doesn't need to do aliasing anymore.
>
> In other words, I'm separating mutability and aliasing, so that they
> can't combine and explode.
This would seem to be identical to what I am proposing.
> > Let's say I have an
> > employee database. John Smith just got hired on 1/1/2006 with
> > a salary of $10,000. I need to record this fact somewhere. How
> > do I do that without variables? Current-employees is a variable.
> > Even if I have the space to keep all historical data, so I'm not
> > deleting anything, I still have to have a variable for the latest
> > version of the accumulated data. I can solve this without
> > pointers, but I can't solve it without variables.
>
> As I said elsewhere, the record has an identity even though it isn't
> explicit in SQL.
Hmmmm. What can this mean?
In general, I feel that "records" are not the right conceptual
level to think about.
In any event, I am not sure what you mean by non-explicit
identity. I would say, records in SQL have value, and their
identity is exactly their value. I do not see that they have
any identity outside of their value. We can uniquely identify
any particular record via a key, but a table may have more
than one key, and an update may change the values of one
key but not another. So it is not possible in general to
definitely and uniquely assign a mapping from each record
of a table after an update to each record of the table before
the update, and if you can't do that, then where
is the record identity?
(The situation is even more dire when one considers that
SQL actually uses bag semantics and not set semantics.)
[...]
> > I should like to learn more about these. I have some vague
> > perception of the existence of linear logic, but not much
> > else. However, I also already have an excellent solution
> > to the pointer aliasing problem, so I'm less motivated.
>
> Pointers are just the most obvious form of aliasing. As I said
> elsewhere, there are others: array indexing, by-reference parameters, or
> even WHERE clauses in SQL statements. In fact, anything that selects an
> updatable piece of data from a collection is an alias, and incurs the
> same problems as pointers, though they may come in different disguises.
Okay. At this point, though, the term aliasing has become extremely
general. I believe "i+1+1" is an alias for "i+2" under this definition.
That is so general that I am concerned it has lost its ability to
identify problems specific to pointers.
> >> Actually SQL has references - they are called "primary keys", but they
> >> are references nevertheless.
> >
> > I strongly object; this is quite incorrect. I grant you that from the
> > 50,000 foot level they appear identical, but they are not. To
> > qualify as a reference, there need to be reference and dereference
> > operations on the reference datatype; there is no such operation
> > is SQL.
> >
> > Would you say the relational algebra has references?
>
> Yes.
>
> > Or, consider the classic prolog ancestor query. Let's say we're
> > setting up as follows
> >
> > father(bob, joe).
> > father(joe, john).
> >
> > Is "joe" a reference, here? After all, when we do the ancestor
> > query for john, we'll see his father is joe and then use that to
> > find joe's father. Keys in SQL are isomorphic to joe in the
> > above prolog.
>
> Agreed. They are both references ;-P
Again, by generalizing the term this far, I am concerned with a
loss of precision. If "joe" in the prolog is a references, then
"reference" is just a term for "data" that is being used in a
certain way. The conection with a specfic address space
has been lost in favor of the full domain of the datatype.
> >> (Some SQL dialects also offer synthetic
> >> "ID" fields that are guaranteed to remain stable over the lifetime of a
> >> record.
> >
> > Primary keys are updatable; there is nothing special about them.
>
> Right - I was wrong with identifying keys and identities. In fact the
> identity of an SQL record cannot be directly obtained (unless via those
> ID fields).
> The records still have identities. It's possible to have two WHERE
> clauses that refer to the same record, and if you update the record
> using one WHERE clause, the record returned by the other WHERE clause
> will have changed, too.
Is this any different from saying that an expression that includes
a variable will produce a different value if the variable changes?
In other words, "i+1" will return a different value if we update i.
It seems odd to me to suggest that "i+1" has identity. I can see
that i has identity, but I would say that "i+1" has only value.
But perhaps the ultimate upshoot of this thread is that my use
of terminology is nonstandard.
> >> With a "repeatable read" isolation level, you actually return to a
> >> declarative view of the database: whatever you do with it, you won't see
> >> it until you commit the transaction. (As soon as you commit, the
> >> declarative peace is over and you better watch out that your data
> >> doesn't become inconsistent due to aliasing.)
> >
> > Alas, transaction isolation levels are a performance hack.
> > I cannot defend them on any logical basis. (Aside: did you mean
> > serializable, rather than repeatable read?)
>
> Possibly. There are so many isolation levels that I have to look them up
> whenever I want to get the terminology 100% correct.
Hmmm. Is it that there are so many, or that they are simply not
part of our daily concern? It seems to me there are more different
styles of parameter passing than there are isolation levels, but
I don't usually see (competent) people (such as yourself) getting
call-by-value confused with call-by-reference.
> >> The only thing that can really be done about it is not adding it
> >> artificially into a program. In those cases where aliasing is part of
> >> the modelled domain, you really have to carefully inspect all
> >> interactions and never, never, never dream about abstracting it away.
> >
> > Yes, aliasing introduces a lot of problems. This is one reason
> > why closures make me nervous.
>
> Me too.
> On the other hand, they are so immensely useful.
> Simply don't create closures with mutable data in them. Or, to the very
> least, make sure that no aliases outside the closure exist.
Thank you for the interesting exchange.
Marshall
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 9476
***************************************