[26095] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8295 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 31 18:05:41 2005

Date: Sun, 31 Jul 2005 15:05:03 -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           Sun, 31 Jul 2005     Volume: 10 Number: 8295

Today's topics:
        Coding Conventions and Speech: No Punctuation, Renaming <vtatila@mail.student.oulu.fi>
        OLE Automation of OmniPage 12: Newbie Qs <vtatila@mail.student.oulu.fi>
    Re: OLE Automation of OmniPage 12: Newbie Qs <sisyphus1@nomail.afraid.org>
        sendmail Help Please jane@rifill.com
    Re: sendmail Help Please <tintin@invalid.invalid>
    Re: sendmail Help Please jane@rifill.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 31 Jul 2005 14:11:35 +0300
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Coding Conventions and Speech: No Punctuation, Renaming Operators etc...
Message-Id: <dcibl9$is5$1@news.oulu.fi>

Hi,
I realize this is not the optimal newsgroup for questions like this but 
thought I'd give it a shot anyway. That is I'm a sight impaired guy doing 
programming mostly as a hobby and have recently found Perl to cut a long 
story short. Now, I'm wondering if there are any style guides that would 
focus on making the code as easy to read as possible for screen reader 
users. I don't intend to distribute my code anywhere just yet so being 
friendly to the sighted reader as well is not of primary concern at the 
moment. So here are some observations of mine as well as a question or two. 
Any and all comments are welcome.

I have a bit of sight left in my left eye  but am still primarily a screen 
reader user and legally blind, too. Synthetic speech, full-screen 
magnification at 5x or more and braile being the primary output media in 
this order. Unlike most people I'm not using the Jaws screen reader in 
Windows but a British reader and magnifier called Supernova. For the 
interested reader, the home of Supernova is:

http://www.dolphinuk.co.uk/

And info on my sight can be found here.

http://www.student.oulu.fi/~vtatila/sight.html

As there are people with varyin levels of sight and having different tastes, 
I reckon the use of the screen reader differs quite a bit. One Weakness of 
Supernova is that the punctuation levels are preset so you cannot 
selectively ignore certain punctuation. Thus it is pretty much a none or all 
affair. Setting punctuation to all reads all operators, parentheses and so 
on but is tiering to listen to

while($_ = <IN>)

becomes

while left paren dollar underline equals less than in greater than right 
paren

Sure you get use to this style of operation and it is the same nuisance with 
almost any language apart from, perhaps SQL.

The alternative is to turn punctuation off completely so you get:

while in

This is nicer but heavily ambiguous regarding what operators and variables 
are used inside the parentheses. Still it is all right if you are writing 
short snippets of code and can recall what certain piece of code ought to be 
doing approximately. I've found that comments can help, too. Still I need to 
occasionally check some punctuation and tend to do this with magnification 
or braille. IT is slow but this method has worked well, so far.

Now I'm basically thinking of what kind of steps could be used to get Perl 
code easier and less ambiguous if reading with speech and punctuation set to 
none. Here's what I've found out so far although many of these habits 
haven't yet caught on in my case and I'm realizing new things when writing 
this:

1. It is advisible to get rid of as much punctuation as possible.

a. Leave out parentheses when-ever possible.

b. Use the English module. So in stead of undef we get undef input record 
separator. Note the exact spelling as punctuation is not read and case 
changes or underlines are taken to be word delimiters.

c. Perl supports and, or and not in stead of the horrible ampersand 
ampersand etc... as in C or Java. Use the verbal forms.

d. Learn to use q, qq and qw to represent quotes unambiguously as well as 
comment regexp. Verbal character classes read nicer than a-zA-Z.

e. Short loops in which the body becomes before the loop or condition being 
tested are preferrable, because you can fit things naturaly on one line and 
get rid of redundant braces. Functional programming ala map and grep should 
also be encouraged when-ever it fits the problem and can omit braces.

f. Comment ending braces to make it explicit when a block ends. Often I use 
the keyword of the condition or loop or the name of the current sub. as in

sub marine
{ # A demonstration function doing nothing at all.
   # do stuff
} # marine

Notice the braces. I've never quite gotten into the K&R style of bracing. 
One benefit of this left brace on its own line style is that you can attach 
short comments naturally as in explaining some condition, decision, 
rationale etc...

Still it would be even cooler in my view if you could omit braces 
completely. I don't like the Pascal style but Python is not bad in this 
regard apart from eval-ing code I guess. So can you get some Perl module 
that let's you omit braces or adds them just prior to parsing the program?

2. Naming variables and functions.

a. Many of the Perl language functions sound like natural language which I 
like. That is things like die, split and so on. There are some problematic 
cases, though. I don't generally like shortenings such as eval or errno as 
they sound silly on a speech synth 'e-vul and 'err, no'. Eval is especially 
close to evil so for a long long time before using Perl I thought Unix 
shells and Perl had an evil function, hehe.

b. On a similar note some operators are problematic, too. Most string ops 
are read out nicely but arithmetic is not and must almost always be checked 
out with braille, magnification or cursoring in characters using speech.

Is it possible, feasible or easy to redefine some function names in a file 
once and include that file to be used in my own scripts? I'm new to modules. 
I'm not thinking of renaming many of the built-in functions but arithmetic 
would be easier to read with the following mappings (reckon you could do 
them as defines in C):
+ plus
* times
/ divided by
% modulo
< less
> greater
== equals
= is
 .. to
and so on
I cannot change the reading of punctuation in the screen reader, at least on 
a per app basis.

c.  It would be preferrable if the variable name indicated naturally the 
type of the variable without having to check the initial sign dollar, at or 
percent. One basic way is to use single forms for scalars and plurals or the 
suffix list for arrays as in $scalar, @scalars, @scalarList (the last two 
are arrays). For hashes things are not as easy. I prefer to name them so 
that they indicate the nature of the mapping %keys2values e.g. 
%strings2lengths. You can also turn the concept upside down by saying 
%valueByKey as in %personById.

d. For references, file handles etc... I still need to think of good 
conventions. You can make the readre beep case differences but that soon 
gets annoying, too, so upper-case handle names are not automatically 
distinguished. Maybe the suffixes File and Dir or some identifier as in 
Hungarian notation such as h for handles, and r for references could be 
used. I generally dislike Hungarian notation, though, as sometimes word-like 
constructs are read as words and at other times not. that is CALLWNDPROC and 
HINSTANCE are read as words so it sounds like rubbish (well that's what 
Win32 is, only kidding though).

e. As to OOP stuff, which I haven't done in Perl yet but know Java, I like 
the prefixes my for object variables and their for class variables. 
Sometimes I also use the Epoc-inspired form aParameter in method parameters. 
I reckon this is a as in argument but I sometimes also read it as the 
article a. AS in we know the actual parameter passed but from the function's 
point of view that is just aParameter out of several possible values that 
could be passed.

f. I'm all for named arguments using hashes when it makes the code natural 
to read. One of the most beautiful examples so far is one I accidentally 
found on Larry's site:

move $rook from => $qr_pos, to => "kb3";

This reads out very well using speech even if punctuation is set to none.

3. Other ideas.
a. Though no punctuation is read, certain punctuation characters are implied 
by changes in intonation. This is somewhat speech synth dependent but with 
Dolphin orpheus v2 the following holds. Comma and colon translate to a short 
pause with no change in intonation. This is nice in argument lists and 
labels among other things. A question mark raises the pitch slightly so the 
question colon operator is hinted at by the speech. The exclamation mark 
adds a short pause and lowers the pitch so it could be succesfully used as a 
delimiter in tr, m and so on. Finally, this is most likely a long-standing 
bug but with the current version of Orpheus a single quote surrounded by 
white space (/s) is read out even if punctuation is set to none. I'm not 
sure if any uses for this quirk could be found. Maybe to mark comments in 
some way.

b. If you hav any ideas on how to make Perl more speech friendly using 
modules or coding conventions, I would appreciate your input. I might even 
do a style guide that emphasizes ease-of-use with speech. Of course coding 
practises like this are merely to make Perl as nice and cosy to code in as 
possible at home. For any production code, there's usually a strict style 
guide to follow and variation is not permitted.

With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/ 




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

Date: Sun, 31 Jul 2005 12:01:16 +0300
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: OLE Automation of OmniPage 12: Newbie Qs
Message-Id: <dci40u$hrf$1@news.oulu.fi>

Hi,
This is my first post in this group. Hope it is all right to ask app 
specific questions here about OLE, even if Perl is not the culprit. I first 
tried the group comp.os.ms-windows.programmer.ole but it is almost dead 
compared to this one.

I'm pretty much a newbie as far as OLE and COM goes having only done some
basic automation of SAPI 5 and Auto It from Perl. I own Scansoft
OmniPage 12 and discovered on the Internet that the office version should
support OLE automation. However, I also found out with the help of the
Visual Studio 6 Ole View app that my version 12, which is not the office
edition at all, does seem to have quite a number of methods and properties
that one could use.

Basic methods like AppName and AppInitialized do work. However, I get a
null-reference when trying to do anything useful at all such as create a
document. I found some sample VB code by Googling the news and based on that
tried the following Perl snippet:

use strict;
use OLE;
$/ = "\n";
my $op = CreateObject OLE 'Omnipage12' or die "OLE Error: $!\n";
print "This is " . $op->AppName() . ' v' . $op->Version . "";
my $process = $op->Login('');
warn "App not initialized" unless($op->AppInitialized());
my $result = $process->CreateDocument();
print "Result: $result";

Something definitely does happen when running this. The version and app name
is as expected, the input focus moves temporarily out of the DOS window and
I can hear the hard drive working for a while.

There are two problems, though. Firstly I'm not sure what should be passed
to the login function. No matter what I pass, it never reports that OmniPage
has been initialized succesfully.

The OLE viewre gives the following:

[id(0x00000005), helpstring("Initialize OmniPage for automation")]
IDispatch* Login([in] BSTR Key);

Umm a pointer to the IDispatch interface and a function taking a String name
Key. But what's this bit about the bracketed [in]?

Secondly, perl says that $process has the value undef hinting that something
went wrong early on. I reckon this is a direct consequence of the login
failing but again am not totally sure.

To understand OmniPage OLE automation better I've been trying to find the
official Scansoft docs on it with no luck so far. Neither my version 12
manual nor the version 14 office PDF manual mention OLE automation, oh well.

Has anyone managed to get OmniPage 12 OLE automation working and if so what
am I doing wrong?

Further more, would be great if someone could give a definite answer on
whether OLE Automation is supported in Omni Page version 12 that does not
have the label Office appended to the name. The methods are there as I said
but with my luck they have probably been criplled in some way. If Login
shall always return NULL, for instance, I suppose there's not anything I can
do.

By the way, I'm running Win XP SP2 and Active State Perl 5.8.6 in case that
has any significance.

On a side note, the reason why I'm trying automation in the first place is
that I'd like a quick means of converting a screenshot to speech being sight
impaired. If I could do a little perl script that does the job it might help
a great deal in interpreting textual but image based content quickly without 
having to
fall back to full-screen magnification, or manual OCRing for that matter.

Any help greatly appreciated as usual.

-- 
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/




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

Date: Sun, 31 Jul 2005 20:15:57 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: OLE Automation of OmniPage 12: Newbie Qs
Message-Id: <42eca50c$0$25984$afc38c87@news.optusnet.com.au>


"Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi> wrote in message
news:dci40u$hrf$1@news.oulu.fi...
> Hi,
> This is my first post in this group. Hope it is all right to ask app
> specific questions here about OLE, even if Perl is not the culprit.

The perl-win32-users mailing hosted by ActiveState is probably a better
forum. (To subscribe, visit http://aspn.activestate.com/ASPN/Mail/ . Mention
"OLE" in the subject line of your post if you send mail there. That will
improve the chances of getting an informed response.)

Beyond that ..... I can't really help - though there may be others here who
can.

Cheers,
Rob




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

Date: Sun, 31 Jul 2005 15:13:11 GMT
From: jane@rifill.com
Subject: sendmail Help Please
Message-Id: <04qpe1tjn7nk4fles8h1c46tadlcbt5c0d@4ax.com>

Hi 

WInXp Pro
Apache2
Argosoft Mailserver

I have a perl script in the config file I have

#$config{'mailprog'} = '/usr/sbin/sendmail -t';

$config{'mailhost'} = 'localhost'; # UNCOMMENT THIS LINE IF YOU NEED A MAIL HOST (SMTP)


As you see I have the bottom one selected.

I send email form the script and all works ok

BUT then I look in the argosoft logs and i Get


Transmission did not end with "." on a line by itself. Disconnecting...


After I fill the mail form out in the script and press send it goes to  sub sendemail


So what is argosoft asking for?

Transmission did not end with "." on a line by itself. Disconnecting..

What should I put for the "."



sub sendemail {
        my ($to,$from,$subject,$message) = @_;
        my $trash;
        if ($config{'mailhost'}) {
		eval('use IO::Socket; 1;') or &oops("IO::Socket could not be loaded by the
script. Perl version $].  IO::Socket may not be included with versions of perl prior to
5.00404.");
                my $remote;
                $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
                $remote->autoflush();
                print $remote "HELO\r\n";
                $trash = <$remote>;
                print $remote "MAIL From:<$config{'admin_address'}>\r\n";
                $trash = <$remote>;
                print $remote "RCPT To:<$to>\r\n";
                $trash = <$remote>;
                print $remote "DATA\r\n";
                $trash = <$remote>;
                print $remote "From: <$from>\r\nSubject: $subject\r\n\r\n";
                print $remote $message;
                print $remote "\r\n.\r\n";
                $trash = <$remote>;
                print $remote "QUIT\r\n";
        }
        else {
                open MAIL, "|$config{'mailprog'}";
                print MAIL "To: $to\nFrom: $from\nSubject: $subject\n$message\n";
                close MAIL;
        }


Thank you

Jane


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

Date: Mon, 1 Aug 2005 07:57:29 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: sendmail Help Please
Message-Id: <I2aHe.4869$PL5.438854@news.xtra.co.nz>


<jane@rifill.com> wrote in message 
news:04qpe1tjn7nk4fles8h1c46tadlcbt5c0d@4ax.com...
> Hi
>
> WInXp Pro
> Apache2
> Argosoft Mailserver
>
> I have a perl script in the config file I have
>
> #$config{'mailprog'} = '/usr/sbin/sendmail -t';
>
> $config{'mailhost'} = 'localhost'; # UNCOMMENT THIS LINE IF YOU NEED A 
> MAIL HOST (SMTP)
>
>
> As you see I have the bottom one selected.
>
> I send email form the script and all works ok
>
> BUT then I look in the argosoft logs and i Get
>
>
> Transmission did not end with "." on a line by itself. Disconnecting...
>
>
> After I fill the mail form out in the script and press send it goes to 
> sub sendemail
>
>
> So what is argosoft asking for?

It's asking exactly what the line below says.

>
> Transmission did not end with "." on a line by itself. Disconnecting..
>
> What should I put for the "."

For the ".", you need to put a ".", ie:  a dot on a line by itself.

[snipped low level SMTP code that would be better done using one of the 
higher level mail modules]

I assume this is not your code?




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

Date: Sun, 31 Jul 2005 20:19:06 GMT
From: jane@rifill.com
Subject: Re: sendmail Help Please
Message-Id: <v3cqe15mebbf38m1ubqdgee0m2d8k09e96@4ax.com>

On Mon, 1 Aug 2005 07:57:29 +1200, "Tintin" <tintin@invalid.invalid> wrote:

>
><jane@rifill.com> wrote in message 
>news:04qpe1tjn7nk4fles8h1c46tadlcbt5c0d@4ax.com...
>> Hi
>>
>> WInXp Pro
>> Apache2
>> Argosoft Mailserver
>>
>> I have a perl script in the config file I have
>>
>> #$config{'mailprog'} = '/usr/sbin/sendmail -t';
>>
>> $config{'mailhost'} = 'localhost'; # UNCOMMENT THIS LINE IF YOU NEED A 
>> MAIL HOST (SMTP)
>>
>>
>> As you see I have the bottom one selected.
>>
>> I send email form the script and all works ok
>>
>> BUT then I look in the argosoft logs and i Get
>>
>>
>> Transmission did not end with "." on a line by itself. Disconnecting...
>>
>>
>> After I fill the mail form out in the script and press send it goes to 
>> sub sendemail
>>
>>
>> So what is argosoft asking for?
>
>It's asking exactly what the line below says.
>
>>
>> Transmission did not end with "." on a line by itself. Disconnecting..
>>
>> What should I put for the "."
>
>For the ".", you need to put a ".", ie:  a dot on a line by itself.


So where in the script do i put that please.

At the end of 

 print $remote $message;
                print $remote "\r\n.\r\n";
                $trash = <$remote>;
                print $remote "QUIT\r\n";

LIKE         "."

OR 

                $trash = <$remote>;
                "."
                print $remote "QUIT\r\n";
 

OR 

                $trash = <$remote>;
                print "."
                print $remote "QUIT\r\n";

#####################################


>
>[snipped low level SMTP code that would be better done using one of the 
>higher level mail modules]

Sorry what do you mean on th above

>
>I assume this is not your code?

You Assume Correct.

Regards

Jane







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

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


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