[28090] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9454 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 12 11:05:39 2006

Date: Wed, 12 Jul 2006 08: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           Wed, 12 Jul 2006     Volume: 10 Number: 9454

Today's topics:
    Re: converting line input into columns vanagas99@yahoo.com
        Dereferencing Hash of Arrays <jennifer.drake@gmail.com>
    Re: Dereferencing Hash of Arrays <aukjan@gmail.com>
    Re: Dereferencing Hash of Arrays <jennifer.drake@gmail.com>
    Re: finding perl info on google can be hard <sherm@Sherm-Pendleys-Computer.local>
    Re: finding perl info on google can be hard <sherm@Sherm-Pendleys-Computer.local>
    Re: global variables in a web service <sgt19@tid.es>
    Re: global variables in a web service <rvtol+news@isolution.nl>
    Re: global variables in a web service anno4000@radom.zrz.tu-berlin.de
    Re: global variables in a web service <tadmc@augustmail.com>
    Re: Inline missing with ActiveState? <bol@adv.magwien.gv.at>
    Re: Inline missing with ActiveState? <sigzero@gmail.com>
    Re: multiple array parameters to object methods? en2guy@hotmail.co.uk
    Re: Problem with Multi- threaded Server <tzz@lifelogs.com>
    Re: RSS feeds and HTML special characters <rvtol+news@isolution.nl>
    Re: Strange syntax error <sgt19@tid.es>
    Re: Strange syntax error <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: What is a type error? <jo@durchholz.org>
    Re: What is a type error? <jo@durchholz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 12 Jul 2006 06:07:08 -0700
From: vanagas99@yahoo.com
Subject: Re: converting line input into columns
Message-Id: <1152709628.277066.289360@b28g2000cwb.googlegroups.com>


Tad McClellan wrote:
> vanagas99@yahoo.com <vanagas99@yahoo.com> wrote:
> >
> > A. Sinan Unur wrote:
> >> vanagas99@yahoo.com wrote in
> >> news:1152496902.511701.167670@p79g2000cwp.googlegroups.com:
> >>
> >> >
> >> > Tad McClellan wrote:
> >> >> vanagas99@yahoo.com <vanagas99@yahoo.com> wrote:
> >> >>
> >> >> > sorry,
> >> >>
> >> ...
> >>
> >> >> It is pretty clear that your "sorry" is not at all sincere,
>
>
> >> > Great addition to my perl learning experience.....
>
>
> You do not have a Perl learning experience.
>
> If you did, you would have posted the Perl that you've learned,
> and we would have helped you fix it.
>
> You have a "fix my program for me" experience.
>
>
> > I didn't even know what
> > "posting on top" means...
>
>
> So you didn't even know what you you were apologizing for then?
>
>
> > plus, blabing about the sincerity of my
> > "sorry"???
>
>
> Appearing to apologize while not even knowing what it is about
> is pretty clearly insincere.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

Tad, what's the matter? are you heart? need a hug? So I made a mistake.
Bid deal... Get over already. Move on, buddy..

Thanks to all other guys for trying to help me. I am making progress.

AV



------------------------------

Date: 12 Jul 2006 06:50:52 -0700
From: "Jennifer I. Drake" <jennifer.drake@gmail.com>
Subject: Dereferencing Hash of Arrays
Message-Id: <1152712252.230018.192980@h48g2000cwc.googlegroups.com>

Hello,

I created a hash of arrays and I'm having problems dereferencing the
array and printing the array out.  In one subroutine, I create the hash
and put the data into it.  From that subroutine, I call another
subroutine and pass the reference to the hash.  In the second
subroutine, I sort the hash and try to dereference the arrays.  But,
when I try to print the arrays, nothing appears.  I know that there is
data in the original array given to the hash and I know that the hash
keys are valid.  Any help would be appreciated with where I've gone
wrong.

Thanks!
-Jen

#!/usr/bin/perl
use strict;
use warnings;

my %keys;
&GetData(\%keys);

###subroutine 1 - GetData###

### Retrieving information from a PostgreSQL database here.
my %data;
my $keysRef;

foreach my $secondKey (@{$secondKeysRef}) {
   while (($key, @values) = $sth->fetchrow_array) {
         $$keysRef{$key} = 1;
         $data{$key}{$secondKey} = \@values;
   }
   &StoreData(\%data, $keysRef);
}


###subroutine 2 - StoreData###

my ($dataRef, $keysRef) = @_;

my $outputfile = "Output.txt";
open (OUT, ">$outputfile") or die "Cannot make $outputfile: $!\n";

foreach my $key (sort keys %{$dataRef}) {  ##loop through each of the
first key

   print OUT $key;

   for (my $i = 0; $i<3; $i++) {  ##loop through each of the second
keys - hardcoded for now, but will be a variables to control count
later

      my $valuesRef = $$dataRef{$key}{$$keysRef[$i]};
      print OUT "\t";
      print OUT join ("\t", @$valuesRef);
  }
  print OUT "\n";
}



------------------------------

Date: Wed, 12 Jul 2006 16:03:24 +0200
From: Aukjan van Belkum <aukjan@gmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <18b89$44b50107$c2abfc64$21645@news1.tudelft.nl>


> 
> my %keys;
> &GetData(\%keys);
> 
> ###subroutine 1 - GetData###
> 
> ### Retrieving information from a PostgreSQL database here.
> my %data;
> my $keysRef;
> 
>

Jen,

You give an argument to the subroutine GetData, but never assign it to 
any variable. This might be your problem. I assume you want the 
'$keysRef' to contain the reference, so you should change 'my $keysRef;' 
to 'my $keysRef = shift;'.

Also please include your complete code (including 'sub GetDAta { etc...' 
) when posting code, this improves readability.

Aukjan.


------------------------------

Date: 12 Jul 2006 07:15:39 -0700
From: "Jennifer I. Drake" <jennifer.drake@gmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <1152713739.326683.196710@s13g2000cwa.googlegroups.com>

I do have a the 'my ($keysRef) = @_'  in my code.  I tried to remove
some of the code to be more clear.  I guess it has the opposite effect.
 The rest of the code is quite long and contains a lot of
CGI/PostgreSQL calls that don't do anything with this issue, so I
wasn't sure if I should post all of it.  I'll post the complete GetData
and StoreData subroutines.

I've checked all of the variables in the GetData subroutine to make
sure that they have values and aren't referencing empty strings.  The
problem seems to lie either in the way that I am storing data or in the
way that I am dereferencing the data in the 'data' hash.

-Jen

###############################################
sub GetData{
###############################################

	my ($keysRef, $exptIDsRef, $IDToNameRef, $keyToSUIDRef, $SUIDToKeyRef,
$where, $join, $from, $coordsRef, $retrieveBy, $selectedColumn,
$joinHashRef) = @_;

	my $exptnum = scalar(@$exptIDsRef);

	print "Using ", font({-color=>'red'}, "$exptnum"), " experiments and
retrieving from the ", font({-color=>'red'}, "Result"), " table for
each experiment\n", p;

	my ($exptname, $exptid, $seqname);
	my ($key, $spot, $suid, $val, $sth, @values, $keyOffset, %data);

	my $count = 1;

	my $select = "SELECT RESULT.SPOT, RESULT.LOG_RAT2N_MEAN,
RESULT.CH1I_MEAN ";

	$from =~ s/, $//;

	my %reverseExpts;
	&selectReverse($exptIDsRef, \%reverseExpts);
	my $reverseFlag = $query->param('isReverse');

	my $sql = "$select $from $join AND exptid = ? $where $selectedColumn
IS NOT NULL";

	my $sth = $dbh->prepare($sql);

	print "Retrieving data...\n<br>";

	#print "SQL Statement: $sql<br>";
	eval {
		foreach $exptid (@{$exptIDsRef}) {

			print "$count: $$IDToNameRef{$exptid}",br;

			print "Experiment ID: $exptid<br>";
			$sth->execute($exptid);

			while(($spot, @values) = $sth->fetchrow_array) {

				if (($reverseFlag eq 'Y' && $reverseExpts{$exptid} eq 'N') ||
($reverseFlag eq 'N' && $reverseExpts{$exptid} eq 'Y')) {
					for (my $i = 0; $i < scalar(@values); $i++) {
						$values[$i] = -$values[$i];
					}
				}


				$$keysRef{$spot} = 1;
				$data{$spot}{$exptid} = \@values;

			}

			if ((!($count%$numToDump)) || ($count==$exptnum)) {
				print "Caching data to disk...\n";

				&StoreData(\%data, $count, $exptIDsRef, $IDToNameRef);
				undef %data;

			}

			$count++;

		}
	};

	if ($@) {
		my $error = $@;
		print h3("An error occurred in generating a query to retrieve your
data from the database");
		print h4("The most likely cause of this is an incorrectly formatted
filter string.");
		print h4("For your reference, the error was:<br>$error");
		print "If you believe an incorrectly formatted filter string is not
the problem, please let the curators know exactly what you did so they
can reproduce the error.  This will allow the programmers to work on a
fix",br;
		return(1);
	}

	$sth->finish;

	print br;

	&StitchFilesTogether($exptnum, $keysRef, $exptIDsRef, $IDToNameRef);

	return(undef);

}

#########################################################
sub StoreData{
#########################################################

	my ($dataRef, $count, $exptIDsRef, $IDToNameRef) = @_;

	my ($i, $start, $key, $num);

	my %data = %$dataRef;

	my $number = int(($count-1)/$numToDump) + 1;

	my $filename = $$.".".$number.".tmp";

	open (OUT, ">$tmpDir/$filename") or die "Cannot make $tmpDir/$filename
: $!\n",br;

	$start = int(($count-1)/$numToDump) * $numToDump;

	foreach $key (sort keys %data) {

		print OUT $key;

		for ($i = $start; $i<$count; $i++) {

			my $valuesRef = $data{$key}{$$exptIDsRef[$i]};

			print OUT "\t";
			print OUT join ("\t", @$valuesRef);

		}

		print OUT "\n";

		$num++;

		print "$num\n<br>" if (!($num%1000));

	}

	close OUT;

}


Aukjan van Belkum wrote:
> >
> > my %keys;
> > &GetData(\%keys);
> >
> > ###subroutine 1 - GetData###
> >
> > ### Retrieving information from a PostgreSQL database here.
> > my %data;
> > my $keysRef;
> >
> >
>
> Jen,
>
> You give an argument to the subroutine GetData, but never assign it to
> any variable. This might be your problem. I assume you want the
> '$keysRef' to contain the reference, so you should change 'my $keysRef;'
> to 'my $keysRef = shift;'.
>
> Also please include your complete code (including 'sub GetDAta { etc...'
> ) when posting code, this improves readability.
> 
> Aukjan.



------------------------------

Date: Wed, 12 Jul 2006 08:37:18 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: finding perl info on google can be hard
Message-Id: <m2u05nf18h.fsf@Sherm-Pendleys-Computer.local>

ilikesluts@gmail.com writes:

> google (http://www.google.com) is a search engine

Thank you Captain Obvious.

> and is useful for
> finding information on all sorts of topics, not just Perl.

You were just complaining that it's not so useful for finding information
about Perl. Make up your mind.

With a handle like that, I should have known you're a troll and just ignored
you instead of answering. I won't be making *that* mistake again...

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Wed, 12 Jul 2006 08:44:23 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: finding perl info on google can be hard
Message-Id: <m2psgbf0wo.fsf@Sherm-Pendleys-Computer.local>

Ben Morrow <benmorrow@tiscali.co.uk> writes:

> Quoth Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>:
>> 
>> So it looks like seek does some basic sanity checking for arguments that
>> are nonsensical regardless of the file size, but doesn't do a bounds check
>> against the actual file size. That makes sense in the case of a writable
>> file which can be grown to fit the new position, but for a read-only file
>> it's completely non-intuitive.
>
> From my lseek(2):
> | The  lseek  function allows the file offset to be set beyond the end of
> | the existing end-of-file of the file (but this does not change the size
> | of the file).  If data is later written at this point, subsequent reads
> | of the data in the gap return bytes of zeros (until  data  is  actually
> | written into the gap).
>
> So Perl is just reporting what the OS does.

Well, I didn't say it was *wrong*, I just said it was non-intuitive. :-)

Also, fseek(2) doesn't say anything about that on my system, and that's what
I was using as a reference. Lseek(2) reads the same as above though.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Wed, 12 Jul 2006 11:40:32 +0200
From: Stephan Titard <sgt19@tid.es>
Subject: Re: global variables in a web service
Message-Id: <e92g2e$35j2@news.hi.inet>

Tad McClellan escribió:
> David Combs <dkcombs@panix.com> wrote:
> 
>> "Dynamic scoping" -- nice terminology.
> 
>> Larry, of course, has chosen the seemingly opposite-meaning
>> term "local" for the concept in perl.
> 
> 
> The biggest cause of the local() confusion is that "local" is short
> for something, and most folks fillin the wrong something.
> 
> local() makes a "local value", not a "local variable".
> 
> 
yes. Around here I tell people it is short for "localize"

hth
--steph


------------------------------

Date: Wed, 12 Jul 2006 13:44:42 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: global variables in a web service
Message-Id: <e92ufs.1c8.1@news.isolution.nl>

Stephan Titard schreef:
> Tad McClellan:
>> David Combs:

>>> "Dynamic scoping" -- nice terminology.
>>>
>>> Larry, of course, has chosen the seemingly opposite-meaning
>>> term "local" for the concept in perl.
>>
>> The biggest cause of the local() confusion is that "local" is short
>> for something, and most folks fillin the wrong something.
>> local() makes a "local value", not a "local variable".
>
> yes. Around here I tell people it is short for "localize"

In Perl6 it is renamed to "temp" (and also see "let").
http://dev.perl.org/perl6/doc/design/syn/S04.html

-- 
Affijn, Ruud

"Gewoon is een tijger."




------------------------------

Date: 12 Jul 2006 12:06:22 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: global variables in a web service
Message-Id: <4hk6tuF1rfk33U1@news.dfncis.de>

Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> Stephan Titard schreef:

[local()]

> In Perl6 it is renamed to "temp" (and also see "let").

A very good choice.  Dynamic binding is best described in temporal
terms: the value is valid *until* control leaves the block.  Lexical
scope is described in spatial terms: the variable is only accessible
*inside* the block.  In that view, "my" ought to be called "local",
but even Perl6 won't go that far.

Anno


------------------------------

Date: Wed, 12 Jul 2006 07:26:39 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: global variables in a web service
Message-Id: <slrneb9qjv.cbk.tadmc@magna.augustmail.com>

Stephan Titard <sgt19@tid.es> wrote:
> Tad McClellan escribió:
>> David Combs <dkcombs@panix.com> wrote:
>> 
>>> "Dynamic scoping" -- nice terminology.
>> 
>>> Larry, of course, has chosen the seemingly opposite-meaning
>>> term "local" for the concept in perl.
>> 
>> 
>> The biggest cause of the local() confusion is that "local" is short
>> for something, and most folks fillin the wrong something.
>> 
>> local() makes a "local value", not a "local variable".
>> 
>> 
> yes. Around here I tell people it is short for "localize"


I tell them it is short for "save and restore".


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 12 Jul 2006 15:49:05 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: Inline missing with ActiveState?
Message-Id: <1152712146.310322@proxy.dienste.wien.at>

Robert Hicks:

> Add the repository for Randy Kobes:
>
>  http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?url:/PPMServer58

Something seems to be wrong with this URL - I can't see anything.

Can you check the spelling, please?

MTIA & kind greetings,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




------------------------------

Date: 12 Jul 2006 07:46:58 -0700
From: "Robert Hicks" <sigzero@gmail.com>
Subject: Re: Inline missing with ActiveState?
Message-Id: <1152715618.462369.298630@i42g2000cwa.googlegroups.com>


Ferry Bolhar wrote:
> Robert Hicks:
>
> > Add the repository for Randy Kobes:
> >
> >  http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?url:/PPMServer58
>
> Something seems to be wrong with this URL - I can't see anything.
>
> Can you check the spelling, please?
>
> MTIA & kind greetings,
>
> Ferry

You add that in your PPM session:

ppm> rep add theoryx <URL from above>

That will add that repository to your PPM sessions and you will have
"Inline". 

HTH

Robert



------------------------------

Date: 12 Jul 2006 03:48:27 -0700
From: en2guy@hotmail.co.uk
Subject: Re: multiple array parameters to object methods?
Message-Id: <1152701307.541438.269940@35g2000cwc.googlegroups.com>


anno4000@radom.zrz.tu-berlin.de wrote:
> <en2guy@hotmail.co.uk> wrote in comp.lang.perl.misc:
> > Hi-
> >
> > trying to understand object oriented perl, and have been wondering
> > about passing arrays as parameters to object methods.
> >
> > If I pass a single array as a method parameter, it's fine, eg
> >
> > $object->raiseFlags(@flags);
> >
> > However, if I wanted to pass 2 arrays to an object method, I would have
> > to use references to objects, I think, since
>
> Not to objects, necessarily, but array refs are the standard way
> of handing in more than one array to a perl sub.  Whether the sub
> is a method or not is irrelevant.
>
> > $object->raiseFlags(@flags, @specialOccasions);
> >
> > would append @specialOccasions to @flags to make a big jumbled list.
> >
> > Are there any issues to using references as method parameters when
> > using objects in perl?
>
> No.
>
> > Is there a better way to approach the problem?
>
> Other ways, yes.  Better, no.
> 
> Anno

thanks for the feedback, Anno.



------------------------------

Date: Wed, 12 Jul 2006 10:34:02 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Problem with Multi- threaded Server
Message-Id: <g69veq2uc2t.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 11 Jul 2006, xhoster@gmail.com wrote:

> perl -le 'use threads; my @x=1..100_000; foreach (1..10000) { async {
> sleep}->detach(); warn $_ unless $_%100; }'
>
> The above started swapping itself to death between 400 and 500 (and it took
> precious long even to get to 400).
>
> perl -le 'use threads; my @x=1..100_000; foreach (1..10000) {fork or sleep;
> warn $_ unless $_%100; }'
>
> This one rapidly ran up to 4500, at which point I killed it to prevent
> running out of processes.
 ...
> perl -le 'use threads; my @x=1..10; foreach (1..10000) { async {
> sleep}->detach; warn $_ unless $_%100; }'
>
> This seg-faulted at 1200, and took annoying long to get there.
>
> perl -le 'use threads; my @x=1..10; foreach (1..10000) { fork or sleep;
> warn $_;}'
>
> This ran out of processes at 6100, very quickly.
>
> This is perl, v5.8.0 built for i386-linux-thread-multi

Thanks for doing these.  I'm actually very surprised - I never
expected Perl 5's threads to be this bad.  I hope Perl 6 improves on
this (I know it's supposed to).  I guess not enough people use
threads, so this area is just not emphasized by the developers.

OP: you should show these to your boss as definite proof that
threading in Perl is probably worse than fork().

Ted


------------------------------

Date: Wed, 12 Jul 2006 12:36:18 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: RSS feeds and HTML special characters
Message-Id: <e92qfs.1c0.1@news.isolution.nl>

Ben Morrow schreef:

> Firstly, you need to be using perl 5.8.

Please make that 5.8.1+

-- 
Affijn, Ruud

"Gewoon is een tijger."




------------------------------

Date: Wed, 12 Jul 2006 11:53:29 +0200
From: Stephan Titard <sgt19@tid.es>
Subject: Re: Strange syntax error
Message-Id: <e92gqn$35j3@news.hi.inet>

Mumia W. escribió:
> tseitlin@gmail.com wrote:
>> Hello,
>> I get a syntax error I can't explain.
>>
>> The script (reduced version):
>>
>> ###############################
>> use Switch;
>>
>> my $line;
>> if ($line =~ /^Frequency\s+=\s+(\d+)\./){
>> 	$freq = $1/1000000;
>> }
>>
>> #sub for opening files in 'read', 'write' or 'append' mode
>> sub openFile()
>> {
>> 	my ($file, $mode) = @_;
>> 	local *FH;
>> 	switch($mode){
>> 		case 'r'{
>> 			if(!open(FH , $file)){
>> 				print"can't open $file $!";
>> 			return 0;
>> 				}
>> 			}
>> 		case 'w'{
>> 			if(!open(FH , ">$file")){
>> 				print"can't open $file $!";
>> 			return 0;
>> 				}
>> 			}
>> 		case 'a'{
>> 			if(!open(FH , ">>$file")){
>> 				print"can't open $file $!";
>> 			return 0;
>> 				}
>> 			}
>> 		else{
>> 			print"wrong or unsupported mode: use 'r' or 'w'";
>> 			return 0;
>> 		}
>> 	}
>> 	return *FH;
>> }
>>
>> # sub simple_stats {
>>     # my $mean  = $sum_x / $size;
>> # }
>>
>> ###END########
>>
>> The error message:
>>> perl -c test.pl
>> String found where operator expected at test.pl line 14, near "case
>> 'r'"
>>         (Do you need to predeclare case?)
>> syntax error at test.pl line 13, near "){"
>> syntax error at test.pl line 19, near "}"
>> test.pl had compilation errors.
>>
>> Eny of the following eliminates the error:
>> 1. Removing or commenting :
>>     if ($line =~ /^Frequency\s+=\s+(\d+)\./){
>> 	$freq = $1/1000000;
>>     }
>> 2. Removing or commenting the openFile sub.
>> 3. Removing the commented simple_stats sub !!!
>>
>> If any one has an idea, please help! 
>> Thanks.
>>
> 
> Every time I tried to use the Switch module, it caused
> me problems, so I don't use it any more. In particular,
> Switch seems to be incompatible with mod_perl under
> Apache.
> 
> My theory is that Switch interacts with the perl parser
> behind the scenes, and since it's buggy, the effects of
> its modifications to the parser are weird errors.
> 
> Don't use Switch.
> 
actually switch (as perl6 given) is already in 5.9.4-to-be
so don't despair we will have it soon

I wonder if it can be wrapped up in a stand-alone module for the 
impatient (a good question for p5p)

hth
--stephan


------------------------------

Date: Wed, 12 Jul 2006 12:07:47 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Strange syntax error
Message-Id: <nC5tg.6616$ye3.1091@newsread1.news.pas.earthlink.net>

On 07/12/2006 04:53 AM, Stephan Titard wrote:
> Mumia W. escribió:
>> [...]
>> Don't use Switch.
>>
> actually switch (as perl6 given) is already in 5.9.4-to-be
> so don't despair we will have it soon
> 
> I wonder if it can be wrapped up in a stand-alone module for the 
> impatient (a good question for p5p)
> 
> hth
> --stephan

There is already a Switch::Perlish on CPAN, and I even 
wrote a switch subroutine once. However, most of the 
time, Perl's other constructs to simulate switch are 
adequate.



------------------------------

Date: Wed, 12 Jul 2006 15:31:36 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is a type error?
Message-Id: <e92tso$bar$1@online.de>

Marshall schrieb:
> Joachim Durchholz wrote:
>> Marshall schrieb:
>>> Now, I'm not fully up to speed on DBC. The contract specifications,
>>> these are specified statically, but checked dynamically, is that
>>> right?
>> That's how it's done in Eiffel, yes.
>>
>>  > In other words, we can consider contracts in light of
>>> inheritance, but the actual verification and checking happens
>>> at runtime, yes?
>> Sure. Though, while DbC gives rules for inheritance (actually subtypes),
>> these are irrelevant to the current discussion; DbC-minus-subtyping can
>> still be usefully applied.
> 
> Yes, subtyping. Of course I meant to say subtyping.<blush>

No need to blush for that, it's perfectly OK in the Eiffel context, 
where a subclass ist always assumed to be a subtype. (This assumption 
isn't always true, which is why Eiffel has some serious holes in the 
type system. The DbC ideas are still useful though, saying "subtype" 
instead of "subclass" just makes the concept applicable outside of OO 
languages.)

> I can certainly see how DbC would be useful without subtyping.
> But would there still be a reason to separate preconditions
> from postconditions? I've never been clear on the point
> of differentiating them (beyond the fact that one's covariant
> and the other is contravariant.)

There is indeed.
The rules about covariance and contravariance are just consequences of 
the notion of having a subtype (albeit important ones when it comes to 
designing concrete interfaces).

For example, if a precondition fails, something is wrong about the 
things that the subroutine assumes about its environment, so it 
shouldn't have been called. This means the error is in the caller, not 
in the subroutine that carries the precondition.

The less important consequence is that this should be reflected in the 
error messages.

The more important consequences apply when integrating software.
If you have a well-tested library, it makes sense to switch off 
postcondition checking for the library routines, but not their 
precondition checking.
This applies not just for run-time checking: Ideally, with compile-time 
inference, all postconditions can be inferred from the function's 
preconditions and their code. The results of that inference can easily 
be stored in the precompiled libraries.
Preconditions, on the other hand, can only be verified by checking all 
places where the functions are called.

>>> Wouldn't it be possible to do them at compile time? (Although
>>> this raises decidability issues.)
>> Exactly, and that's why you'd either uses a restricted assertion
>> language (and essentially get something that's somewhere between a type
>> system and traditional assertion); or you'd use some inference system
>> and try to help it along (not a simple thing either - the components of
>> such a system exist, but I'm not aware of any system that was designed
>> for the average programmer).
> 
> As to the average programmer, I heard this recently on
> comp.databases.theory:
> 
> "Don't blame me for the fact that competent programming, as I view it
> as an intellectual possibility, will be too difficult for "the
> average programmer"  -you must not fall into the trap of rejecting
> a surgical technique because it is beyond the capabilities of the
> barber in his shop around the corner."   -- EWD512

Given the fact that we have far more need for competently-written 
programs than for competent surgery, I don't think that we'll be able to 
follow that idea.

>>> Mightn't it also be possible to
>>> leave it up to the programmer whether a given contract
>>> was compile-time or runtime?
>> I'd agree with that, but I'm not sure how well that would hold up in
>> practice.
> 
> I want to try it and see what it's like.

So do I :-)

Regards,
Jo


------------------------------

Date: Wed, 12 Jul 2006 16:04:28 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is a type error?
Message-Id: <e92vqc$etv$1@online.de>

Darren New schrieb:
> As far as I understand it, Eiffel compilers don't even make use of 
> postconditions to optimize code or eliminate run-time checks (like null 
> pointer testing).

That's correct.

I think a large part of the reasons why this isn't done is that Eiffel's 
semantics is (a) too complicated (it's an imperative language after 
all), and (b) not formalized, which makes it difficult to assess what 
optimizations are safe and what aren't.

(Reason (c) is that Eiffel compiler vendors don't have the manpower for 
this kind of work, mostly in quantity but also, to some degree, in 
quality: people with a solid language semantics background tend to be 
repelled by the language inventor's know-it-all deny-the-problems 
don't-bother-me-with-formalisms attitude. He still has moved the state 
of the art ahead - mostly by pointing out a certain class of problems in 
OO designs and explaining them lucidly, and proposing solutions that 
hold up better than average even if still fundamentally flawed.)

Regards,
Jo


------------------------------

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 9454
***************************************


home help back first fref pref prev next nref lref last post