[32810] in Perl-Users-Digest
Perl-Users Digest, Issue: 4075 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 12 18:09:45 2013
Date: Tue, 12 Nov 2013 15:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 12 Nov 2013 Volume: 11 Number: 4075
Today's topics:
'depth n' combinations of a sequence of numbers <rweikusat@mobileactivedefense.com>
Re: 'depth n' combinations of a sequence of numbers <gamo@telecable.es>
Re: 'depth n' combinations of a sequence of numbers <derykus@gmail.com>
Re: 'depth n' combinations of a sequence of numbers <blgl@stacken.kth.se>
Re: 'depth n' combinations of a sequence of numbers <rweikusat@mobileactivedefense.com>
Re: 'depth n' combinations of a sequence of numbers <rweikusat@mobileactivedefense.com>
Re: 'depth n' combinations of a sequence of numbers <cwilbur@chromatico.net>
Re: Defining a data structure - is there a standard/bes <cartercc@gmail.com>
Re: Several Perl Questions - Nov. 5, 2013 <cwilbur@chromatico.net>
Re: Several Perl Questions - Nov. 5, 2013 <cwilbur@chromatico.net>
Re: Several Perl Questions - Nov. 5, 2013 (Tim McDaniel)
Re: Several Perl Questions - Nov. 5, 2013 <news@lawshouse.org>
Re: Several Perl Questions - Nov. 5, 2013 <edgrsprj@ix.netcom.com>
Re: Several Perl Questions - Nov. 5, 2013 <edgrsprj@ix.netcom.com>
Re: Several Perl Questions - Nov. 5, 2013 <dave@invalid.invalid>
Re: Several Perl Questions - Nov. 5, 2013 <ben.usenet@bsb.me.uk>
Re: Several Perl Questions - Nov. 5, 2013 <cwilbur@chromatico.net>
Re: Several Perl Questions - Nov. 5, 2013 <news@lawshouse.org>
Re: Several Perl Questions - Nov. 5, 2013 <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Nov 2013 23:21:38 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: 'depth n' combinations of a sequence of numbers
Message-Id: <87ob5qle2l.fsf@sable.mobileactivedefense.com>
For some rather weird problem, I needed a way to generate an ordered
list of all pairs which can be formed from the sequence 0, 1, 2, ... 31.
I figured that it should be possible to write a recursive function
taking a 'ring size' (32 in this case) and a 'depth' (2) argument which
would return a generator cycling through all pairs, with the
function generating the generator being capable of returning a working
result for any combination of size and depth. This turned out to be
amazingly more complicated than I originally thought. The result I came
up with is
---------
sub ring
{
my $size = $_[0];
my $cur;
$cur = -1;
return sub {
return $cur = ($cur + 1) % $size;
}
}
sub rings
{
my ($size, $depth) = @_;
my ($cur, $ring_next, $tail, $last_t0);
$ring_next = ring($size);
return $ring_next if $depth == 1;
$last_t0 = $cur = -1;
$tail = rings($size, $depth - 1);
return sub {
my @tail;
@tail = $tail->();
$cur = $ring_next->() if !$tail[0] && $last_t0;
$last_t0 = $tail[0];
return ($cur, @tail);
};
}
my $r = rings(32, 2);
print(join(',', $r->()), "\n") for 0 .. 1023;
---------
Are there other possibilities?
------------------------------
Date: Tue, 12 Nov 2013 02:07:34 +0100
From: gamo <gamo@telecable.es>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <l5rv0q$7kj$1@speranza.aioe.org>
El 12/11/13 00:21, Rainer Weikusat escribió:
>
> Are there other possibilities?
>
Did you considered using Algorithm::Combinatorics?
It's written in C, with no recursion and based in the literature.
It claims to be efficient, and as far as I tested it is i.e. it
takes the same time to generate all the permutations that the circular
permutations, proportionally.
Best regards
------------------------------
Date: Mon, 11 Nov 2013 22:56:41 -0800
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <l5sjfa$fen$1@speranza.aioe.org>
On 11/11/2013 3:21 PM, Rainer Weikusat wrote:
> For some rather weird problem, I needed a way to generate an ordered
> list of all pairs which can be formed from the sequence 0, 1, 2, ... 31.
> I figured that it should be possible to write a recursive function
> taking a 'ring size' (32 in this case) and a 'depth' (2) argument which
> would return a generator cycling through all pairs, with the
> function generating the generator being capable of returning a working
> result for any combination of size and depth. This turned out to be
> amazingly more complicated than I originally thought. The result I came
> up with is
>
> ---------
> sub ring
> {
> my $size = $_[0];
> my $cur;
>
> $cur = -1;
> return sub {
> return $cur = ($cur + 1) % $size;
> }
> }
>
> sub rings
> {
> my ($size, $depth) = @_;
> my ($cur, $ring_next, $tail, $last_t0);
>
> $ring_next = ring($size);
> return $ring_next if $depth == 1;
>
> $last_t0 = $cur = -1;
> $tail = rings($size, $depth - 1);
>
> return sub {
> my @tail;
>
> @tail = $tail->();
> $cur = $ring_next->() if !$tail[0] && $last_t0;
> $last_t0 = $tail[0];
>
> return ($cur, @tail);
> };
> }
>
> my $r = rings(32, 2);
>
> print(join(',', $r->()), "\n") for 0 .. 1023;
> ---------
>
> Are there other possibilities?
perl -E 'use constant PERM => join ",",0..31;say join "\n",
glob "{@{[PERM]}},{@{[PERM]}}"'
--
Charles DeRykus
------------------------------
Date: Tue, 12 Nov 2013 09:40:51 +0100
From: Bo Lindbergh <blgl@stacken.kth.se>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <l5spij$lsq$1@dont-email.me>
In article <87ob5qle2l.fsf@sable.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> For some rather weird problem, I needed a way to generate an ordered
> list of all pairs which can be formed from the sequence 0, 1, 2, ... 31.
> I figured that it should be possible to write a recursive function
> taking a 'ring size' (32 in this case) and a 'depth' (2) argument which
> would return a generator cycling through all pairs, with the
> function generating the generator being capable of returning a working
> result for any combination of size and depth. This turned out to be
> amazingly more complicated than I originally thought.
> Are there other possibilities?
Since Perl has arrays, iteration is simpler than recursion for this problem.
sub rings
{
my($size,@values);
$size=int(shift(@_));
@values=(0) x shift(@_);
sub
{
my(@result);
@result=@values;
$_=($_+1)%$size and last for reverse @values;
@result;
};
}
Or, as stated elsewhere in this thread, use Algorithm::Combinatorics.
/Bo Lindbergh
------------------------------
Date: Tue, 12 Nov 2013 12:39:30 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <87mwl9aj5p.fsf@sable.mobileactivedefense.com>
Bo Lindbergh <blgl@stacken.kth.se> writes:
> In article <87ob5qle2l.fsf@sable.mobileactivedefense.com>,
> Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
>> For some rather weird problem, I needed a way to generate an ordered
>> list of all pairs which can be formed from the sequence 0, 1, 2, ... 31.
>> I figured that it should be possible to write a recursive function
>> taking a 'ring size' (32 in this case) and a 'depth' (2) argument which
>> would return a generator cycling through all pairs, with the
>> function generating the generator being capable of returning a working
>> result for any combination of size and depth. This turned out to be
>> amazingly more complicated than I originally thought.
>
>> Are there other possibilities?
>
> Since Perl has arrays, iteration is simpler than recursion for this
> problem.
Sorry but this was not a "Help me! I'm lost!" question. I was
specifically looking for a recursive solution.
> sub rings
> {
> my($size,@values);
>
> $size=int(shift(@_));
> @values=(0) x shift(@_);
> sub
> {
> my(@result);
>
> @result=@values;
> $_=($_+1)%$size and last for reverse @values;
> @result;
> };
> }
There are some things about this code I really dislike, eg, the $size =
int(shift(@_)) instead of the equivalent $size = $_[0]. Also, you're not
treating the initial state specially despite it is special which means
the code has to do an intermediate copy of the result array. But the
for-loop is decidedly a good idea. Combining some parts of both leads to
----------
sub rings
{
my ($size, @tuple);
$size = $_[0];
@tuple = (-1) x $_[1];
return sub {
$_ = ($_ + 1) % $size and last for reverse(@tuple);
return @tuple;
}
}
----------
Which is what I will likely actually use.
> Or, as stated elsewhere in this thread, use Algorithm::Combinatorics.
I understand that "download shit from the internet" (and stitch that
together by applied ingenuity aka 'bizarre workarounds nobody
understands') is some people's natural first reaction to any programming
problem and I won't begrudge them the (commercial) successes they
achieve in this way with "our free software who runs your company",
however, I don't care about that because I know that I will have to
maintain this 'shit' at some point in time and fixing bugs in
unfamiliar code takes longer than writing code in many cases (I don't do
"fire, bill got paid, anything else not my problem, forget" jobs).
Since the same people usually can't stop showing off their impressive
downloading skills, I've instructed my newsreader to stop them for me
:-).
------------------------------
Date: Tue, 12 Nov 2013 12:51:45 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <87iovxaila.fsf@sable.mobileactivedefense.com>
Charles DeRykus <derykus@gmail.com> writes:
> On 11/11/2013 3:21 PM, Rainer Weikusat wrote:
>> For some rather weird problem, I needed a way to generate an ordered
>> list of all pairs which can be formed from the sequence 0, 1, 2, ... 31.
>> I figured that it should be possible to write a recursive function
[...]
>> Are there other possibilities?
>
>
> perl -E 'use constant PERM => join ",",0..31;say join "\n",
> glob "{@{[PERM]}},{@{[PERM]}}"'
Again, I wanted a recursive solution. But this is nevertheless a neat
idea. In somewhat demystified from, it looks like this:
perl -E 'say(join("\n", glob(sprintf("{%s},{%s}", (join(",", 0 .. 31)) x 2))))'
which is based on using so-called 'brace expansion' to create a
cartesian product (is this the right term?) of n sets. The drawback
would be that this is a rather memory intense process which means that
perl -E 'say(join("\n", glob(sprintf("{%s},{%s},{%s},{%s},{%s}", (join(",", 0 .. 31)) x 5))))'
pushes the computer where I ran this (512M) into thrashing while the
equivalent, array-based routine I posted in the other reply produces the
result set with constant memory usage in about 5s (as do the other two,
albeit they take somewhat longer).
------------------------------
Date: Tue, 12 Nov 2013 11:42:33 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: 'depth n' combinations of a sequence of numbers
Message-Id: <87wqkd4lmu.fsf@new.chromatico.net>
>>>>> "RW" == Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
RW> There are some things about this code I really dislike, eg, the
RW> $size = int(shift(@_)) instead of the equivalent $size =
RW> $_[0].
Those are not, strictly speaking, equivalent.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 11 Nov 2013 13:33:44 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Defining a data structure - is there a standard/best practice way?
Message-Id: <6cef6543-2516-4d34-a20d-23b874103335@googlegroups.com>
On Monday, November 11, 2013 5:22:44 AM UTC-5, Justin C wrote:
> I am writing a module which interacts with a database. It is only
> able to perform certain types of query, and return data in certain
> formats (I'm not opening up the whole of DBIx for users of the
> module - if they want to do more then my module isn't for them).
I frequently have great big globs of data that I need to print/export in pa=
rticular ways. Aside from the fact that the requirements of your printing/e=
xporting activity is EXTREMELY important, I customarily start with stuffing=
all the data in a single hash \ref. I then print the hashref in a simple A=
SCII file, which allows me to look at the data and determine how I want to =
print it out.
For example, a very simple example, suppose my data file looks like this:
ID,NAME,COLLEGE,PROGRAM,LEVEL,TERM,COURSE,GPA,CREDITS,RESTRICTIONS
use Text::ParseWords;
my %bighash;
#first, grab all the data and stuff it into memory
while (<IN>)
{
my($ID,$NAM,$COL,$PRO,$LEV,$TER,$COU,$GPA,$CRE,$RES)
$bighash{$COL}{$LEV}{$PRO}{$TER} =3D {
ID =3D> $ID,
NAM =3D> $NAM,
COL =3D> $COL,
PRO =3D> $PRO,
LEV =3D> $LEV,
TER =3D> $TER,
COU =3D> $COU,
GPA =3D> $GPA,
CRE =3D> $CRE,
RES =3D>$RES, };
}
# now, print all the data out
while (<OUT>)
{
foreach my $COL (sort keys %bighash) {
foreach my $LEV (sort keys %{$bighash{$COL}}) {
foreach my $PRO (sort keys %{$bighash{$COL}{$LEV}}) {
foreach my $TER (sort keys %{$bighash{$COL}{$LEV}{$PRO}) {
foreach my $key (sort keys %{$bighash{$COL}{$LEV}{$PRO}{$TER}) {
print OUT " $key =3D>$bighash$COL}{$LEV}{$PRO}{$TER}{$KEY}\n";
}}}}}}
=20
Yeah, I know this is mindless, but that's the point. Once you do the mindle=
ss part, you can study your output requirements and construct one or more h=
ashes to conveniently output what you need.
Anyway, this technique works for me, I use it almost every day.
CC.
------------------------------
Date: Mon, 11 Nov 2013 12:10:41 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <87zjpa6ezy.fsf@new.chromatico.net>
>>>>> "HL" == Henry Law <news@lawshouse.org> writes:
HL> On 05/11/13 14:53, Charlton Wilbur wrote:
>> The best way for you to go with graphics, is, in my professional
>> opinion, to hire a competent programmer with experience building
>> web software and leave it to him or her.
HL> Quite so; but quoth EDG in his original post ...
>> There are a number of computer programmers who are involved with
>> what is being discussed here.
Indeed, and I did not miss that; however, there is one critical
adjective and an adjectival prhase of lesser of import in my
recommendation that are nowhere to be found in EDG's statement.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 11 Nov 2013 12:19:28 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <87vbzy6elb.fsf@new.chromatico.net>
>>>>> "HL" == Henry Law <news@lawshouse.org> writes:
HL> (This has to be by far the worst Perl code I've ever seen in my
HL> life).
One: Despite Ben Morrow's correction to my statement that Perl does math
as fast as it can (which I recognize as not so much incorrect as
insufficiently qualified, but Ben can't be expected to know the caveats
I meant to write) my experience with EDG and his code in the past leads
me to believe, first, that there are orders of magnitude of improvement
available without leaving Perl and, second, that steering him towards
some kind of solution that integrates C and Perl will only increase his
frustration and the newsgroup's level of pain.
Two: if your claim is true, you are a fortunate man indeed.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 11 Nov 2013 18:13:13 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <l5r6np$nb4$1@reader1.panix.com>
In article <cLCdnah5cpChoeTPnZ2dnUVZ7sednZ2d@giganews.com>,
Henry Law <news@lawshouse.org> wrote:
>The version of your code that I looked at ...
>
>(This has to be by far the worst Perl code I've ever seen in my life).
May I ask how I might see that code? (Unseeing it is, of course, not
your problem.)
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Mon, 11 Nov 2013 22:24:50 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <YdWdnX5AEr-vxBzPnZ2dnUVZ7tCdnZ2d@giganews.com>
On 11/11/13 18:13, Tim McDaniel wrote:
>> (This has to be by far the worst Perl code I've ever seen in my life).
>
> May I ask how I might see that code? (Unseeing it is, of course, not
> your problem.)
You can download a version from
http://www.freewebz.com/eq-forecasting/301.html but it's been packaged
up into a Windows .exe file, from which it takes a little ingenuity to
extract Perl, and even then it seems to have had some of the text changed.
I'm basing my opinion on an earlier version, as a result of an earlier
thread; that was plain Perl. I doubt the actual code has changed much.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 12 Nov 2013 03:18:31 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <fb6dnTB00IP5bxzPnZ2dnUVZ_vydnZ2d@earthlink.com>
"Scott Bryce" <sbryce@scottbryce.com> wrote in message
news:l5g81b$rro$1@dont-email.me...
> On 11/6/2013 11:50 PM, E.D.G. wrote:
>> The newest version of the WWWBoard that I know of was finally
>> selected and developed for use.
>
> Hopefully, you got this from NMS, and not from Matt.
Correct. The version that I modified was from the following Web
site:
http://nms-cgi.sourceforge.net/
------------------------------
Date: Tue, 12 Nov 2013 04:10:02 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <UeadnQjSw-zvYxzPnZ2dnUVZ_hidnZ2d@earthlink.com>
"E.D.G." <edgrsprj@ix.netcom.com> wrote in message
news:CKWdneJtr5yvpebPnZ2dnUVZ_g6dnZ2d@earthlink.com...
Posted by E.D.G. on November 12, 2013
There were several comments in posts here regarding the Perl code in
my earthquake research and forecasting programs.
First, the actual code available as text code on one of my Web sites
was not intended to be efficient "Perl language" code. Instead it was
intended to tell other researchers around the world how to do certain types
of calculations. And it was written using an extremely simple format so
that the code could be easily translated to other languages. The following
explains the importance of that.
One of the people that I work with and I are using an important
computer program that is quite unique. It was created a long time ago by a
highly regarded scientist who passed away a while back. And he made three
copies of the program available for people as free downloads. The first is
an exe version of the program that will run on any Windows machine. The
second is the code for the program written using what is now an ancient
version of Fortran. And the third is for the same program using an ancient
version of Basic.
The professional programmer and I attempted to produce versions of
the program using a modern language. I managed the project and the
programmer did the actual work. And unfortunately, in spite of his many
years of experience he could not understand the Fortran and Basic versions
to the point where he could translate them. I recommended that he post some
notes to the Fortran Newsgroup and ask if anyone visiting that Newsgroup had
an instruction manual for that ancient version of Fortran that would explain
what the program code meant. But for some reason he chose not to do that.
And it would have taken me a considerable amount of time to attempt the
translation myself.
So, the end result is that when the program needs to generate data,
the exe version is used "as is." Or it is called from a Perl program and
given the input information it needs so that it can generate data.
The point is, when people want to make some computer program
available for use by others around the world they might want to circulate a
version of their program that has such a simple format that anyone can
understand it. And for actual use they can generate parallel versions that
have more efficient code that people who are working with that language can
understand.
Regarding the Perl code in the exe version of the earthquake research
and forecasting program that is available at one of my Web sites, the
present version is now much more advanced. But even that older version was
simply intended to let people generate certain types of data. It "got the
job done" without any effort to be elegant. And part of the idea was to
show that certain types of data could actually be generated. If governments
and researchers around the world liked the data then they could create other
versions of the program that would have carefully constructed code.
------------------------------
Date: Tue, 12 Nov 2013 10:24:03 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <fV45K0OBJxbE-pn2-mu0DSdnDEw4S@paddington.bear.den>
On Tue, 12 Nov 2013 10:10:02 UTC, "E.D.G." <edgrsprj@ix.netcom.com>
wrote:
> One of the people that I work with and I are using an important
> computer program that is quite unique. It was created a long time ago by a
> highly regarded scientist who passed away a while back. And he made three
> copies of the program available for people as free downloads. The first is
> an exe version of the program that will run on any Windows machine. The
> second is the code for the program written using what is now an ancient
> version of Fortran. And the third is for the same program using an ancient
> version of Basic.
>
I used to speak Fortran :-) Got a link to the code?
--
Regards
Dave Saville
------------------------------
Date: Tue, 12 Nov 2013 12:32:51 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <0.6d3e16a0f5094abe41d2.20131112123251GMT.87bo1pssuk.fsf@bsb.me.uk>
"E.D.G." <edgrsprj@ix.netcom.com> writes:
<snip>
> [...] And unfortunately, in spite of his
> many years of experience he could not understand the Fortran and Basic
> versions to the point where he could translate them. I recommended
> that he post some notes to the Fortran Newsgroup and ask if anyone
> visiting that Newsgroup had an instruction manual for that ancient
> version of Fortran that would explain what the program code meant.
I imagine the problem was due to non-standard extensions. Even ancient
standard Fortran would be understandable (maybe with documentation) to a
modern Fortran programmer. Is the code publicly available?
<snip>
--
Ben.
------------------------------
Date: Tue, 12 Nov 2013 11:40:50 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <871u2l60a5.fsf@new.chromatico.net>
>>>>> "EDG" == E D G <edgrsprj@ix.netcom.com> writes:
EDG> First, the actual code available as text code on one of my Web
EDG> sites was not intended to be efficient "Perl language" code.
EDG> Instead it was intended to tell other researchers around the
EDG> world how to do certain types of calculations. And it was
EDG> written using an extremely simple format so that the code could
EDG> be easily translated to other languages.
Well, then: you have decided that simplicity of expression is more
important than performance. The two are not always opposed, but the
belief that they are quickly becomes a self-fulfilling prophecy.
EDG> The professional programmer and I attempted to produce
EDG> versions of the program using a modern language. I managed the
EDG> project and the programmer did the actual work. And
EDG> unfortunately, in spite of his many years of experience he
EDG> could not understand the Fortran and Basic versions to the
EDG> point where he could translate them.
This sounds to me as if you and I have remarkably different standards
for "professional programmer."
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 12 Nov 2013 20:50:33 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <a5-dnY7NK6IHCR_PnZ2dnUVZ8gudnZ2d@giganews.com>
On 12/11/13 10:10, E.D.G. wrote:
> now an ancient version of Fortran
That explains (but IMO doesn't excuse) a lot about the code. First
thing I thought when I tried, and failed, to read it through is that it
looks like FORTRAN written in Perl: the lack of indentation; the GOTO
statements; and the labels used to implement loops. Like this fragment.
> getdatalines:; # start and return point of loop to process another test file line - includes next 15 lines
> $num1 = $num + 1;
> if ($num1 > 1000){goto programerror};# at end of program
> $dataline[$num1] = $word;
> $charnum = -1;
> $word = "";
> $num = $num + 1;
> $numdatalines = $num;
> if (substr($tlin[$num], 0, 45) eq '***** END OF THE CONTROL SETTINGS SECTION ***'){goto processtestdata2};
> # the above line jumps about 8 lines down when the extract data lines routine ends
> nextchar:;# start of and return point to get settings values - includes next 8 lines
> $charnum = $charnum + 1;
> $char = substr($tlin[$num],$charnum,1);
> if ($char eq " " || $char eq "," || $char eq ""){goto getdatalines};
> # the above line jumps back to start of routine about 15 lines up
> $word = $word.$char;
> goto nextchar;# jump 6 lines up to test another character
... etc
But if you wanted to make it easy to translate into other programming
languages then some kind of structured algorithmic representation (which
I've heard of but know nothing about), or even good ol' indented
pseudocode, might have been better.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 12 Nov 2013 13:23:29 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Several Perl Questions - Nov. 5, 2013
Message-Id: <o76589p7fo5oa56s29p6fc7mvoq6k5e6f8@4ax.com>
Henry Law <news@lawshouse.org> wrote:
>On 12/11/13 10:10, E.D.G. wrote:
>> now an ancient version of Fortran
>
>That explains (but IMO doesn't excuse) a lot about the code. First
>thing I thought when I tried, and failed, to read it through is that it
>looks like FORTRAN written in Perl: the lack of indentation; the GOTO
>statements; and the labels used to implement loops. Like this fragment.
>
>> getdatalines:; # start and return point of loop to process another test file line - includes next 15 lines
>> $num1 = $num + 1;
>> if ($num1 > 1000){goto programerror};# at end of program
>> $dataline[$num1] = $word;
>> $charnum = -1;
>> $word = "";
>> $num = $num + 1;
>> $numdatalines = $num;
>> if (substr($tlin[$num], 0, 45) eq '***** END OF THE CONTROL SETTINGS SECTION ***'){goto processtestdata2};
>> # the above line jumps about 8 lines down when the extract data lines routine ends
>> nextchar:;# start of and return point to get settings values - includes next 8 lines
>> $charnum = $charnum + 1;
>> $char = substr($tlin[$num],$charnum,1);
>> if ($char eq " " || $char eq "," || $char eq ""){goto getdatalines};
>> # the above line jumps back to start of routine about 15 lines up
>> $word = $word.$char;
>> goto nextchar;# jump 6 lines up to test another character
Oh my $DEITY !!!
Are there really people writing code like this? This would have been bad
code 30 years ago. It would have gotten a clear "Fail" in any of my
classes 20 years ago. And it surely hasn't improved with age since.
Recommendation: if this snippet is representative of the rest of the
code then dump it and don't walk but run away as fast as you can. This
code is worse than junk and long overdue for a complete rewrite from
scratch.
And no, there is no indentation missing in this snippet. Thanks to the
horrible style all the lines actually do begin on the correct level. And
that is a bad, bad indicator when all your code is left-aligned.
jue
------------------------------
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 4075
***************************************