perl to english

B

buildmorelines

Is there any script or pragma or something that will translate perl
code to pure english, like that perl latin module, just in english. I
want to show a person who cant read perl code or any computer
language, some perl code, so they have remotly a clue what the code
does or how it flows. It doesnt need to perfectly make sense or be
proper english sentences. Just soemthing that will translate perl code
and/or syntax to english.
 
U

Uri Guttman

b> Is there any script or pragma or something that will translate perl
b> code to pure english, like that perl latin module, just in english. I
b> want to show a person who cant read perl code or any computer
b> language, some perl code, so they have remotly a clue what the code
b> does or how it flows. It doesnt need to perfectly make sense or be
b> proper english sentences. Just soemthing that will translate perl code
b> and/or syntax to english.

what perl latin module? if you mean damain's perligata, that let's you
write perl as latin. it does not translate perl to latin.

and even if you did translate code to english, it still takes a
programmer to understand programming logic. ever heard of cobol? it was
never understood by the manager types which was its intended goal.

uri
 
J

John Bokma

buildmorelines said:
Is there any script or pragma or something that will translate perl
code to pure english, like that perl latin module, just in english. I
want to show a person who cant read perl code or any computer
language, some perl code, so they have remotly a clue what the code
does or how it flows. It doesnt need to perfectly make sense or be
proper english sentences. Just soemthing that will translate perl code
and/or syntax to english.

Uhm, isn't Perl not already English enough?
 
O

Octo Mancer

ever heard of cobol? it was
never understood by the manager types which was its intended goal.

"Each language has its purpose, however humble. Each language expresses
the Yin and Yang of software. Each language has its place within the Tao.
But do not program in COBOL if you can avoid it. "
 
P

Peter Hickman

buildmorelines said:
Is there any script or pragma or something that will translate perl
code to pure english, like that perl latin module, just in english. I
want to show a person who cant read perl code or any computer
language, some perl code, so they have remotly a clue what the code
does or how it flows. It doesnt need to perfectly make sense or be
proper english sentences. Just soemthing that will translate perl code
and/or syntax to english.

Anybody who understands the sentence "dereference and iterate over a list of
anonymous hashes" is probably not far off being able to read perl anyway. To
understand that is probably more than most suits are capable of. Stick to good
documentation and tests.
 
H

Helgi Briem

Is there any script or pragma or something that will translate perl
code to pure english, like that perl latin module, just in english. I
want to show a person who cant read perl code or any computer
language, some perl code, so they have remotly a clue what the code
does or how it flows. It doesnt need to perfectly make sense or be
proper english sentences. Just soemthing that will translate perl code
and/or syntax to english.

Well written Perl is already as close to English as code gets.

--
Helgi Briem hbriem AT simnet DOT is

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
S

Sherm Pendley

wana said:
How about writing English
comments mixed in with your code and write a program that can extract and
format the comments? Has anyone tried doing that?

The comments you're talking about here are called "POD", and the program
to extract them is called "perldoc". There are also a number of pod2foo
programs for translating the comments into other formats.

sherm--
 
U

Uri Guttman

w> In my opinion, SQL is slightly closer to English than Perl. But
w> then again, SQL is a 4G language and Perl is 3G I think. How about
w> writing English comments mixed in with your code and write a
w> program that can extract and format the comments? Has anyone tried
w> doing that?

sql close to english? as cobol is also close? did you read my comment on
how useless english is to describing program logic? ever heard of
ambiguities in language? my favorite (especially in poorly written
technical documentation) is dangling pronouns. which previous thing does
'it' refer to?

so again, you are barking up the wrong tree. this has been tried many
times and is doomed to failure. natural languages are not good for
logical flow descriptions and only perl is good for program poetry!

uri
 
M

Malcolm Dew-Jones

buildmorelines ([email protected]) wrote:
: Is there any script or pragma or something that will translate perl
: code to pure english, like that perl latin module, just in english. I
: want to show a person who cant read perl code or any computer
: language, some perl code, so they have remotly a clue what the code
: does or how it flows. It doesnt need to perfectly make sense or be
: proper english sentences. Just soemthing that will translate perl code
: and/or syntax to english.

I don't know the name of the project, and I suspect it is _written_ in
perl, not _tranlating_ perl.

However, there was a project that converted program code into proper
english.

The object was to prove that computer code is an expression of an idea,
not merely functional, and therefore (in the U.S.) protected. This came
about due to issues around the licensing of DVD code and the intention of
the owners of the code to prevent people from being allowed to read copies
of the code. (not whether they could _use_ the code, but whether they
could even be allowed to _read_ the code).

The argument was that by proving computer code expresses ideas, they would
have proved that people can not be prevented from reading (and discussing
etc) those ideas.

So, googling over dvd topics might find something.
 
A

Anno Siegel

[programming languages that look like English]
so again, you are barking up the wrong tree. this has been tried many
times and is doomed to failure. natural languages are not good for

The latest attempt is AppleScript or, more generally, OS dialects.
I have only seen AppleScript, and it's horror, just *because* it
tries to look like English.
logical flow descriptions and only perl is good for program poetry!

Oh, come on. There must be some Cobol poetry. Something long
and impenetrable, in hexameter...

Anno
 
T

Tad McClellan

It is possible! I have written and tested a preliminary version of the
program that performs the task you are requesting. Here it is:
ReplaceInFile('=', 'is equal to', $file);

I tested it on several perl scripts and it worked beautifully.


Seems to me that it should be either:

ReplaceInFile('==', 'is numerically equal to', $file);
or
ReplaceInFile('eq', 'is stringwise equal to', $file);
or
ReplaceInFile('=', 'gets the value', $file);
 
T

Tintin

wana said:
It is possible! I have written and tested a preliminary version of the
program that performs the task you are requesting. Here it is:

#! /usr/bin/perl

use STD; #my home made module

Oooohhh, please share this module!!

I'm surprised it's not on CPAN yet.
use strict;
use warnings;

my $file = $ARGV[0];
ReplaceInFile('=', 'is equal to', $file);

I tested it on several perl scripts and it worked beautifully.

I bet I could give you some scripts that it wouldn't work beautifully on.
 
P

Peter Scott

Oh, come on. There must be some Cobol poetry. Something long
and impenetrable, in hexameter...

There is the classic COBOL version of Goldilocks and the
Three Bears, which I was introduced to over 20 years ago...
 
U

Uri Guttman

w> use strict;
w> use Exporter;

use base 'Exporter' ;

w> use vars qw /$VERSION @ISA @EXPORT @EXPORT_OK/;

no need for @ISA with use base.
no need for @EXPORT_OK as you don't use it.

w> @ISA = qw /Exporter/;

handled by use base

w> @EXPORT = qw /LoadFromFile SaveToFile
w> Trim ReplaceInFile read_dir/;

our @EXPORT

w> @EXPORT_OK = qw //;

why have that if it is empty?

w> ($VERSION) = '$first attempt: 1.0 $' =~ /(\d+\.\d+)/;

w> #subs start here

really? i couldn't have figured that out without that comment.

w> sub LoadFromFile

don't use studly caps for subnames. in perl that is only used for
package names.

w> #takes array reference and file name as argument
w> #and clears array and fills array with file contents
w> {
w> my ($array, $filename) = @_;

the filename is usually the more important arg and so it should come
first. that way you can also take an optional hash of args
afterwards. see File::Slurp for that style of API.

w> sub Trim
w> #takes reference to scalar and removes leading
w> #and trailing white space.
w> {
w> my $string = shift;
w> ${$string} =~ s/^\s+//;
w> ${$string} =~ s/\s+$//;
w> }

do you realize that @_ is really aliases to the original arguments? you
could simplify that by passing in the real scalars and directly
operating on them.

sub trim {
$_[0] =~ s/^\s+//;
$_[0] =~ s/\s+$//;
}

w> sub ReplaceInFile
w> #takes 4 strings as arguments. the first is the string to replace.
w> #the second is the string to replace with. the third is the file
w> #to search through. the fourth is the file to write to (can be the
w> #same file of course. Leave out 4th arg to use same file.
w> {
w> my ($target, $source, $infile, $outfile) = @_;
w> $outfile = $infile if not defined $outfile;
w> my @workspace;
w> LoadFromFile(\@workspace,$infile);
w> s/$target/$source/g for(@workspace);
w> SaveToFile(\@workspace,$outfile);
w> }

if you slurp, why not slurp in as a single string and then do the
s///. it is much faster than looping over the lines (also scalar
slurping is much faster then line slurping). here is what i would do:
(this is a very simple sub and it could use work)

use File::Slurp ;

sub replace_in_file {

my( $file, $from, $to ) = @_ ;

my $text = read_file( $file ) ;
$text =~ s/$from/$to/g ;
write_file( $file, $text ) ;
}


w> sub read_dir
w> #arguments: directory path and array reference
w> #action: fill array with file names of directory
w> {
w> my ($dir, $return) = @_;
w> @{$return} = ();

why that? just build up an array and return its reference.

w> print "dir = $dir\n";
w> opendir DIR, "$dir" or die "Couldn't open $dir: $!";
w> my @contents = readdir(DIR);
w> closedir DIR or die "Error closing $dir: $!";
w> foreach(@contents)
w> {
w> if (/^\.+/) {next;}
w> else
w> {
w> push @{$return}, $_;
w> }
w> }

blech. perldoc -f grep.

uri
 
P

Paul Lalli

Uri Guttman said:
w> use strict;
w> use Exporter;

use base 'Exporter' ;

w> use vars qw /$VERSION @ISA @EXPORT @EXPORT_OK/;

no need for @ISA with use base.
no need for @EXPORT_OK as you don't use it.

w> @ISA = qw /Exporter/;

handled by use base

I have to admit I didn't know about this. (I knew about base, it just
didn't occur to me to use it here, in contrast to Exporter's docs). I
wonder if it might be worth suggesting the documentation for Exporter.pm
be updated to reflect this method?

Paul Lalli
 
B

buildmorelines

Peter Hickman said:
Anybody who understands the sentence "dereference and iterate over a list of
anonymous hashes" is probably not far off being able to read perl anyway. To
understand that is probably more than most suits are capable of. Stick to good
documentation and tests.

Anybody who understands the sentence "dereference and iterate over a list of
anonymous hashes" is probably not far off being able to read perl anyway.

Is exactly what I want. I dont really want to explain $, @, {}, (), &,
%, /, //, \, \n, ? :, ;, , , =>, [], =, !, ==, =~, !~, =+, >, <, "",
'', ``, @ARGV, @_, $^O, ->, #, ||, &&, regexp markup, and so on. The
only programming experiance this person ever had was a tiny bit of
playing with Flash 4 Action Script, so they slightly get the idea of
programming, but dont know any syntax.
 
T

Tassilo v. Parseval

Also sprach Paul Lalli:
I have to admit I didn't know about this. (I knew about base, it just
didn't occur to me to use it here, in contrast to Exporter's docs). I
wonder if it might be worth suggesting the documentation for Exporter.pm
be updated to reflect this method?

I made this suggestion once in the past and had to learn about some
urban legends according to which 'use base qw/Exporter/' might not
always work as one would expect. Of course, no one was able to come with
an example, let alone explanation, for this alleged dysfunctionality.

Tassilo
 
R

Richard Kofler

Peter said:
There is the classic COBOL version of Goldilocks and the
Three Bears, which I was introduced to over 20 years ago...

make that 30 years ago - I am not this young anymore :)

dic_k
 
B

Bradd W. Szonye

Tim Hammerquist said:
You'd think so, but to hear pythonistas tell it, you'd think we were
programming in Asgard.

I suppose that's better than programming in Goa'uld.
 
P

Peter Scott

Also sprach Paul Lalli:

I made this suggestion once in the past and had to learn about some
urban legends according to which 'use base qw/Exporter/' might not
always work as one would expect. Of course, no one was able to come with
an example, let alone explanation, for this alleged dysfunctionality.

How about the thread at http://tinyurl.com/3z669 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top