[23847] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6050 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 22:57:28 2004

Date: Thu, 29 Jan 2004 19:51:23 -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           Thu, 29 Jan 2004     Volume: 10 Number: 6050

Today's topics:
    Re: Using perl for a limited shell <mikee@mikee.ath.cx>
    Re: Using perl for a limited shell (Walter Roberson)
    Re: Using perl for a limited shell (Malcolm Dew-Jones)
    Re: Using perl for a limited shell (Richard Williams)
    Re: Using perl for a limited shell <j.g.karssenberg@student.utwente.nl>
    Re: Using Perl to input username and password for websi (John)
    Re: Using Perl to Interface with other programs <usenet@morrow.me.uk>
    Re: using variables as hashes ctcgag@hotmail.com
    Re: using variables as hashes <usenet@morrow.me.uk>
        When is a program too big for one file? $_@_.%_
    Re: When is a program too big for one file? (Walter Roberson)
    Re: When is a program too big for one file? $_@_.%_
        Where are lexical Filehandles documented? <gls@byu.edu>
    Re: Where are lexical Filehandles documented? <usenet@morrow.me.uk>
    Re: Where are lexical Filehandles documented? <tadmc@augustmail.com>
    Re: Where are lexical Filehandles documented? <eric-amick@comcast.net>
    Re: Where are lexical Filehandles documented? <gls@byu.edu>
    Re: Where is "split on '.'" documented? (J.B. Moreno)
    Re: Where is "split on '.'" documented? <eric-amick@comcast.net>
        Win32::OLE Code needed <edgrsprj@ix.netcom.com>
    Re: Win32::OLE Code needed <usenet@morrow.me.uk>
    Re: Win32::OLE Code needed <edgrsprj@ix.netcom.com>
    Re: Win32::OLE Code needed <usenet@morrow.me.uk>
    Re: Win32::OLE Code needed <invalid-email@rochester.rr.com>
    Re: Win32::OLE Code needed (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Jan 2004 18:44:09 -0000
From: Mike <mikee@mikee.ath.cx>
Subject: Re: Using perl for a limited shell
Message-Id: <101dcbp8qc2o696@corp.supernews.com>

In article <mr-1919AE.19035027012004@news.fu-berlin.de>, Sandman wrote:
> Would perl be a good course to take if I wanted to create a limited shell for a 
> person logged into linux/unix?
> 
> I'm thinking a while(<>) loop that takes commands and have a "ok" list who 
> pipes them to an external process (such as "ls").
> 
> Would it be possible to launch applications that "take over" the screen in such 
> an environment? Such as pine.
> 
> Just a wild idea I got before checking out other ways to limit a users shell. 
> Any other ideas would also be appriceated. :)
> 

There was a project in the past few years about turning perl into an os.


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

Date: 27 Jan 2004 19:04:41 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Using perl for a limited shell
Message-Id: <bv6co9$s74$1@canopus.cc.umanitoba.ca>

In article <mr-1919AE.19035027012004@news.fu-berlin.de>,
Sandman  <mr@sandman.net> wrote:
:Would perl be a good course to take if I wanted to create a limited shell for a 
:person logged into linux/unix?

:I'm thinking a while(<>) loop that takes commands and have a "ok" list who 
:pipes them to an external process (such as "ls").

You might want to look on cpan.org for the various 'BBS' programs.


:Would it be possible to launch applications that "take over" the
:screen in such an environment? Such as pine.

Yes, but you have to be careful, as many such programs have "shell escapes"
that could allow users to break out of their box.
-- 
   Beware of bugs in the above code; I have only proved it correct,
   not tried it.                             -- Donald Knuth


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

Date: 27 Jan 2004 11:46:20 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Using perl for a limited shell
Message-Id: <4016c00c@news.victoria.tc.ca>

Sandman (mr@sandman.net) wrote:
: Would perl be a good course to take if I wanted to create a limited shell for a 
: person logged into linux/unix?

Not sure, but before you do, look for similar efforts already done.  There 
is at least one fully working shell written using perl (psh ? really not 
sure), and I think several others as well.

: I'm thinking a while(<>) loop that takes commands and have a "ok" list who 
: pipes them to an external process (such as "ls").

ouch

: Would it be possible to launch applications that "take over" the screen in such 
: an environment? Such as pine.

yes

: Just a wild idea I got before checking out other ways to limit a users shell. 
: Any other ideas would also be appriceated. :)

how about a regular shell in restricted mode (rsh, rksh, bash with an
option or started via the correct name - look them all up to be sure).

(rsh is commonly referred to as a "remote" shell, but do not be confused,
it's the same program, if you allow someone to access you _remotely_ you
typically want them to have a _restricted_ environment within which to
work)


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

Date: Wed, 28 Jan 2004 17:23:41 +0000 (UTC)
From: rdwillia@hgmp.mrc.ac.uk (Richard Williams)
Subject: Re: Using perl for a limited shell
Message-Id: <bv8r6s$o8t$1@niobium.hgmp.mrc.ac.uk>

In article <bv6co9$s74$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>:Would it be possible to launch applications that "take over" the
>:screen in such an environment? Such as pine.
>
>Yes, but you have to be careful, as many such programs have "shell escapes"
>that could allow users to break out of their box.

Pine itself is (or at least was) one such program (indirectly) - e.g. if 
the user configures pine to use vi as the 'alternate editor', and your 
version of vi has a shell escape...

Richard.


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

Date: Thu, 29 Jan 2004 18:17:29 +0100
From: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl>
Subject: Re: Using perl for a limited shell
Message-Id: <20040129181729.34ca1bf2@Captain>

You could take the framework of the Zoidberg shell
<http://zoidberg.sf.net>, turn off all defaults and write a simple
plugin that checks commands in your "ok list". Though the framework is
not yet entirely stable and might be a bit heavy for what you had in
mind.

-- 
   )   (     Jaap Karssenberg || Pardus [Larus]                | |0| |
   :   :     http://pardus-larus.student.utwente.nl/~pardus    | | |0|
 )  \ /  (                                                     |0|0|0|
 ",.*'*.,"   Proud owner of "Perl6 Essentials" 1st edition :)  wannabe


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

Date: 19 Jan 2004 15:36:51 -0800
From: alkalox@hotmail.com (John)
Subject: Re: Using Perl to input username and password for website?
Message-Id: <3303a2cb.0401191536.526ce2da@posting.google.com>

Arvin Portlock <apollock11@hotmail.com> wrote in message news:<buhc4a$2iam$1@agate.berkeley.edu>...


Thanks everyone for your suggestions. I used the LWP::UserAgent route and
it worked. Thanks Arvin, your example was very helpful. Thanks to
gnari as well and everyone who posted in the thread.


John


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

Date: Wed, 21 Jan 2004 18:24:41 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Using Perl to Interface with other programs
Message-Id: <bumg59$7e9$1@wisteria.csv.warwick.ac.uk>


Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com> wrote:
> Depending on how jolt does this, the easiest way might be to start jolt
> as an output filter to perl or, if the underlying OS permits, use a
> pipeline in the system command:
> open JOLT, "| jolt"; print JOLT, "<filename>\n";
                                 ^^
No comma.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: 22 Jan 2004 18:04:03 GMT
From: ctcgag@hotmail.com
Subject: Re: using variables as hashes
Message-Id: <20040122130403.079$7V@newsreader.com>

Ravi Parimi <parimi@nowhere.NO-SPAM_PLEASE.ece.arizona.edu> wrote:
> Hi ,
>
> I have 4 hashes %aries, %taurus, %gemini, %leo, and each hash has
> key=>value pairs like:
>
> $aries{"beta"} = "192.168.2.10"
> $aries{"gamma"} = "192.168.2.11"
> and so on.
>
> I would like to be able to print the contents of each hash without
> explicity looping over the name of each hash.. I did something like:
>
> foreach $foo qw /aries taurus gemini leo/ {
>         foreach $var (keys %foo) {
>                 print "$var => $foo{$var}\n";
>         }
> }
>
> I know it doesnt make sense to do it this way, but is there a way such
> that $foo in the first loop above can become a hash on each iteration
> so that the inner loop works without any problem?

Since you know it doesn't make any sense to do it this way, why
do you still want to do it this way?  If the actual inner loop is
so monstrously hideous that you refuse to alter it to use hashrefs instead
of hashes, then you could do:

foreach my $ddd (\%aries,\%taurus,\%gemini,\%leo) {
  my %foo=%$ddd;
  ### Monstrosity doing unholy things with %foo goes here.
  %$ddd=%foo;
};

I'm ashamed to admit that I've used this shameful hack a few times to make
emergency alterations to god-aweful code that we didn't have time to
re-write.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Thu, 22 Jan 2004 18:09:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: using variables as hashes
Message-Id: <bup3kb$5re$3@wisteria.csv.warwick.ac.uk>


ctcgag@hotmail.com wrote:
> Since you know it doesn't make any sense to do it this way, why
> do you still want to do it this way?  If the actual inner loop is
> so monstrously hideous that you refuse to alter it to use hashrefs instead
> of hashes, then you could do:
> 
> foreach my $ddd (\%aries,\%taurus,\%gemini,\%leo) {
>   my %foo=%$ddd;
>   ### Monstrosity doing unholy things with %foo goes here.
>   %$ddd=%foo;
> };

You don't need the final semi; also, the %$ddd=%foo should be in a
continue block. Alternatively, for real nastiness:

foreach my $ddd \(%aries, %taurus, %gemini, %leo) {
    local *foo = $ddd;
    ### Monstrously unholy things with %foo here.
}

Note to OP[1]: I *would* *not* recommend this.

Ben

[1] and Uri ;)

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
 :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk


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

Date: Tue, 27 Jan 2004 21:11:10 GMT
From: $_@_.%_
Subject: When is a program too big for one file?
Message-Id: <OtARb.12448$x05.11156@nwrdny03.gnilink.net>

HI, this application im currently developing is already
737 lines long, 501 of which are all callbacks.

It is my understanding that there is a way to split
perl programs accross multiple files, but im not sure at what
point one should think about doing this.  Also where would
be a good place to find out about doing this effectively?


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

Date: 27 Jan 2004 21:43:53 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: When is a program too big for one file?
Message-Id: <bv6m2p$30l$1@canopus.cc.umanitoba.ca>

In article <OtARb.12448$x05.11156@nwrdny03.gnilink.net>,  <$_@_.%_> wrote:
:HI, this application im currently developing is already
:737 lines long, 501 of which are all callbacks.

:It is my understanding that there is a way to split
:perl programs accross multiple files, but im not sure at what
:point one should think about doing this.  Also where would
:be a good place to find out about doing this effectively?

There is a school of thought that programs should be at most one
screen-full. And that school of thought grew up in the days when
screens were often not more than 24 lines long.

The more usual perl way would be to split along functional lines.

By the way, if 501 lines are callbacks, could the program perhaps
be re-written to be table-driven ?

-- 
   I don't know if there's destiny,
   but there's a decision!                  -- Wim Wenders (WoD)


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

Date: Wed, 28 Jan 2004 21:03:17 GMT
From: $_@_.%_
Subject: Re: When is a program too big for one file?
Message-Id: <psVRb.7631$bx.1371@nwrdny02.gnilink.net>

Just a quick message to say Thank You to: Walter Roberson and gnari
For their responces, much appreciated.


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

Date: 22 Jan 2004 13:30:47 -0700
From: Greg Snow <gls@byu.edu>
Subject: Where are lexical Filehandles documented?
Message-Id: <tfjwu7jg1zc.fsf@fisher.byu.edu>


I have noticed several references to lexically scoped filehandles in
this group recently, code like:

{
 open my $fh, "path/to/file" or die "couldn't open file: $!";
 ...
}

I want to read up some more on how this works, but have not found
anything in the standard docs about lexical filehandles.  I greped all 
the docs I have 
(tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" in my perl
directory (activestate v5.6.1)) and that only pointed to perlopentut
and perlfaq5 which both only refer to using a non-lexical scalars as
the handle.

So, where are lexically scoped filehandles documented? 

Thanks,

-- 
Greg Snow, PhD                Office: 223A TMCB
Department of Statistics      Phone:  (801) 378-7049
Brigham Young University      Dept.:  (801) 378-4505
Provo, UT  84602              email:  gls@byu.edu


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

Date: Thu, 22 Jan 2004 21:34:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Where are lexical Filehandles documented?
Message-Id: <bupfkp$e23$2@wisteria.csv.warwick.ac.uk>


Greg Snow <gls@byu.edu> wrote:
> 
> I have noticed several references to lexically scoped filehandles in
> this group recently, code like:
> 
> {
>  open my $fh, "path/to/file" or die "couldn't open file: $!";
>  ...
> }
> 
> I want to read up some more on how this works, but have not found
> anything in the standard docs about lexical filehandles.
<snip>
> So, where are lexically scoped filehandles documented? 

perlopentut, "Indirect Filehandles".

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Thu, 22 Jan 2004 16:29:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Where are lexical Filehandles documented?
Message-Id: <slrnc10jm1.b55.tadmc@magna.augustmail.com>

Greg Snow <gls@byu.edu> wrote:
> 
> I have noticed several references to lexically scoped filehandles in
> this group recently, code like:
> 
> {
>  open my $fh, "path/to/file" or die "couldn't open file: $!";
>  ...
> }
> 
> I want to read up some more on how this works, but have not found
> anything in the standard docs about lexical filehandles.  


Try the third paragraph of:

   perldoc -f open

:-)


> I greped all 
> the docs I have 
> (tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" 


What if "filehandle" comes first and "lexical" comes second?

As in:

   If FILEHANDLE is an undefined lexical ("my") variable the 
   variable is assigned a reference to a new anonymous filehandle


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


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

Date: Thu, 22 Jan 2004 23:28:51 -0500
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Where are lexical Filehandles documented?
Message-Id: <pc81105ncssmm5kg5a01imrcg0he1bgtmh@4ax.com>

On 22 Jan 2004 13:30:47 -0700, Greg Snow <gls@byu.edu> wrote:

>
>I have noticed several references to lexically scoped filehandles in
>this group recently, code like:
>
>{
> open my $fh, "path/to/file" or die "couldn't open file: $!";
> ...
>}
>
>I want to read up some more on how this works, but have not found
>anything in the standard docs about lexical filehandles.  I greped all 
>the docs I have 
>(tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" in my perl
>directory (activestate v5.6.1)) and that only pointed to perlopentut
>and perlfaq5 which both only refer to using a non-lexical scalars as
>the handle.
>
>So, where are lexically scoped filehandles documented? 

The only place I've seen it in the 5.6.1 docs is in perldelta, and only
obliquely at that; look for "file and directory handles can be
autovivified".  As other posters have pointed out, the 5.8.x docs do a
better job of documenting it.

-- 
Eric Amick
Columbia, MD


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

Date: 23 Jan 2004 09:41:43 -0700
From: Greg Snow <gls@byu.edu>
Subject: Re: Where are lexical Filehandles documented?
Message-Id: <tfjvfn2fwhk.fsf@fisher.byu.edu>

Tad McClellan <tadmc@augustmail.com> writes:

> Greg Snow <gls@byu.edu> wrote:
> > 
> > I have noticed several references to lexically scoped filehandles in
> > this group recently, code like:
> > 
> > {
> >  open my $fh, "path/to/file" or die "couldn't open file: $!";
> >  ...
> > }
> > 
> > I want to read up some more on how this works, but have not found
> > anything in the standard docs about lexical filehandles.  
> 
> 
> Try the third paragraph of:
> 
>    perldoc -f open
> 
> :-)

Didn't help on my local computer (this change did not make it into the
v5.6.1 perlfunc doc apparently), but I did find it at
http://www.perldoc.org/.  My quick test shows that it does work on my
copy.

Thanks,

> > I greped all 
> > the docs I have 
> > (tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" 
> 
> 
> What if "filehandle" comes first and "lexical" comes second?

Good point, but still didn't help since I don't have a local copy of
the v5.8 docs.

-- 
Greg Snow, PhD                Office: 223A TMCB
Department of Statistics      Phone:  (801) 378-7049
Brigham Young University      Dept.:  (801) 378-4505
Provo, UT  84602              email:  gls@byu.edu


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

Date: Mon, 19 Jan 2004 22:28:45 -0500
From: planB@newsreaders.com (J.B. Moreno)
Subject: Re: Where is "split on '.'" documented?
Message-Id: <1g7ty7q.1s00efp12rxapfN%planB@newsreaders.com>

Michele Dondi <bik.mido@tiscalinet.it> wrote:

> Eric Amick <eric-amick@comcast.net> wrote:
> 
> >>Then the current documentation, even if *not* incorrect or misleading
> >>(as someone else suggested), could be updated to mention that
> >>(generic) plain strings can be used and explain how they will be
> >>treated.
> >
> >The following already appears in the documentation:
> >
> >The pattern /PATTERN/ may be replaced with an expression to specify
> >patterns that vary at runtime.
> >
> >Perhaps it could be modified to point out that any kind of pattern can
> >be done that way.
> 
> I just can't grasp what you mean exactly. I think the key to
> understand it is in the expression "any kind of pattern", but then can
> you expand the concept please?

Anytime you are using a pattern match, instead of PATTERN you could have
$p='PATTERN'; and use $p instead.

For example,  $str =~ s/question/answer/; 

could be written as $q='question'; $str=~ s/$q/answer/;

-- 
JBM
"Everything is futile." -- Marvin of Borg


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

Date: Fri, 23 Jan 2004 18:30:14 -0500
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Where is "split on '.'" documented?
Message-Id: <p8b310598qpforv85ct1k0u5f629n46o8v@4ax.com>

On Tue, 20 Jan 2004 14:30:11 +0100, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

>On Sun, 18 Jan 2004 11:26:13 -0500, Eric Amick
><eric-amick@comcast.net> wrote:
>
>>>Then the current documentation, even if *not* incorrect or misleading
>>>(as someone else suggested), could be updated to mention that
>>>(generic) plain strings can be used and explain how they will be
>>>treated.
>>
>>The following already appears in the documentation:
>>
>>The pattern /PATTERN/ may be replaced with an expression to specify
>>patterns that vary at runtime.
>>
>>Perhaps it could be modified to point out that any kind of pattern can
>>be done that way.
>
>I just can't grasp what you mean exactly. I think the key to
>understand it is in the expression "any kind of pattern", but then can
>you expand the concept please?

I mean that mentioning patterns that vary at runtime makes it sound as
if that is the only time using an expression is allowed, which simply
isn't true.

-- 
Eric Amick
Columbia, MD


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

Date: Sat, 24 Jan 2004 03:42:22 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Win32::OLE Code needed
Message-Id: <yQlQb.22415$i4.11246@newsread1.news.atl.earthlink.net>

It was suggested in an earlier post that I could use Win32::OLE routines to
control Windows applications instead of using Windows Script Host.  I read
the Win32::OLE documentation and agree.  But I but do not understand it.  I
started working with Perl just this past week.

The following is an example of what I would like to do.  If someone can
supply the correct Perl code then that would be appreciated.  If not then I
can still do this by having Perl call subroutines written with a different
type of control program.  And I can learn how to do it the correct way at
some later date.


EXAMPLE:

Open C:\example1.txt, an existing file, using notepad
Open C:\example2.txt, a new file, using notepad
Activate example1.txt
Print the word "practice1" to the screen
Save example1.txt
Activate example 2.txt
Print the word "practice2" to the screen
Save example2.txt
Close (exit) example1.txt
Close example2.txt


CONTROL CODES

Can anyone explain how control codes could be sent to example1.txt while it
is running?

For instance, if I want the cursor to move to the end of the file I would
press and hold Ctrl and then press End on the keyboard.  How could Perl be
instructed to send that code to notepad?

Also, how can an Alt code be sent such as Alt F and then S  (save file)?

As I said, I have another control program which I can use for those types of
things by making them subroutines which Perl can call.  To enter a control
code with that program you just place a "^" before the character or word in
a "SendKey" statement.  Alt is represented by a "!".

The following is the reason for trying to learn how to do all of this:

http://www.freewebz.com/eq-forecasting/90-05.html

That Web page contains quite a few data related to earthquake research.  And
unfortunately there is no single program which can generate all of those
different types of data.  So a variety of programs have to be run, one after
the other.  I have a very slow control program which does that now.  And it
works fine.  But it executes just 1 instruction to perhaps as many as 100 at
the most per second depending upon the complexity of the instruction.  And I
need to get a faster control program running.  Perl looks like a good
choice.  Additionally, I need to improve my calculation speeds (versus using
Basic).  But I already know how to use Perl to do calculations.  Controlling
Windows applications is a little more complicated.





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

Date: Sat, 24 Jan 2004 04:50:11 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Win32::OLE Code needed
Message-Id: <busti3$r2s$1@wisteria.csv.warwick.ac.uk>


"edgrsprj" <edgrsprj@ix.netcom.com> wrote:
> EXAMPLE:
> 
> Open C:\example1.txt, an existing file, using notepad
> Open C:\example2.txt, a new file, using notepad
> Activate example1.txt
> Print the word "practice1" to the screen
> Save example1.txt
> Activate example 2.txt
> Print the word "practice2" to the screen
> Save example2.txt
> Close (exit) example1.txt
> Close example2.txt

I presume this example is simplified; but anyway, what are these
external programs you want to control doing? If you just want to
display a text file on the screen and change it, or have the user
change it, I'd suggest you'd be better off installing Tk (ppm install
Tk) and hacking around with ptked to make it do what you want; or in
general, consider re-implementing these external programs in
Perl. It's *much* easier to control another program when you can get
at its guts. If you have some relatively complex app, of course, this
probably isn't worth the effort, especially as you're not to sure of
Perl yet.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Sat, 24 Jan 2004 06:49:16 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Win32::OLE Code needed
Message-Id: <MzoQb.22623$i4.3779@newsread1.news.atl.earthlink.net>

"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:busti3$r2s$1@wisteria.csv.warwick.ac.uk...

> I presume this example is simplified; but anyway, what are these
> external programs you want to control doing? If you just want to

It would be easier to work with just one control and calculation program if
that is possible.  This would be an example of what it might need to do:

Perl would open text file A which would be the display screen.
It would ask for some input data.
It would store that information in a text file B
It would tell program C to start running.  Program C would read text file B,
generate some data, and store it in text file D.
Perl would read text file D, do some calculations, and print the results to
the display screen.

Then it would increment the data by one and repeat that sequence 20 times.

As the results were generated and displayed they would be checked for
accuracy.  And when the program finished running the display screen text
file would be saved. Or if the results looked unacceptable the program would
be told to stop.  And another run would be started using different data.

It might take an hour for a complete run.  And if the results started to
look bad the program could be stopped and restarted before the entire hour
was wasted.

Right now I am probably using more than a dozen programs to generate the
different types of data.  Things need to be simplified.





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

Date: Sat, 24 Jan 2004 12:17:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Win32::OLE Code needed
Message-Id: <butnoq$9be$1@wisteria.csv.warwick.ac.uk>


"edgrsprj" <edgrsprj@ix.netcom.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:busti3$r2s$1@wisteria.csv.warwick.ac.uk...
> 
> > I presume this example is simplified; but anyway, what are these
> > external programs you want to control doing? If you just want to
> 
> It would be easier to work with just one control and calculation program if
> that is possible.  This would be an example of what it might need to do:
> 
> Perl would open text file A which would be the display screen.
> It would ask for some input data.
> It would store that information in a text file B
> It would tell program C to start running.  Program C would read text file B,
> generate some data, and store it in text file D.
> Perl would read text file D, do some calculations, and print the results to
> the display screen.
> 
> Then it would increment the data by one and repeat that sequence 20 times.
> 
> As the results were generated and displayed they would be checked for
> accuracy.  And when the program finished running the display screen text
> file would be saved. Or if the results looked unacceptable the program would
> be told to stop.  And another run would be started using different data.

Right. I would definitely use Tk for all the display stuff. External
programs can be invoked with system() or Win32::Process (the latter
gives you more control). If you can possibly find console-mode (DOS)
versions of the programs you need, they'll be *much* easier to deal
with; alternatively, if they will take instructions on the command
line rather than through a GUI that would also be possible, though you
would have windows popping up and down all the time, which is a
shame. I really doubt it's worth attempting to 'screen-scrape' a
program which is only designed for interactive GUI use.

Ben


-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Sat, 24 Jan 2004 14:53:41 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Win32::OLE Code needed
Message-Id: <40128620.8040800@rochester.rr.com>

edgrsprj wrote:

> It was suggested in an earlier post that I could use Win32::OLE routines to
> control Windows applications instead of using Windows Script Host.  I read
> the Win32::OLE documentation and agree.  But I but do not understand it.  I
> started working with Perl just this past week.
> 


The first step when using Win32::OLE is to understand the OLE interface 
of the Windoze program you want to interface with.  That effort entails 
finding the documentation for the program's OLE interface, which 
includes such fundamentals as what the program's OLE name is so it can 
be connected to.  In some cases, like Microsoft Office applications, 
that is easy:  open up the VBA stuff in the application and look at the 
OLE browser and the examples in VBA help.  In other cases, like Notepad, 
there is no hint of such documentation.  Are you certain Notepad even 
has an OLE interface?  If it doesn't, perhaps Word or maybe WordPad 
would do what you want?

In any event, all that has nothing to do with Perl.  Once you know the 
OLE interface and could do the job in VB for example, then translating 
that to Perl's Win32::OLE is trivial (it mostly could be done by machine 
-- see the Win32::OLE docs ["perldoc Win32::OLE" at a command prompt] 
for the translation scheme).  Maybe you could ask about Notepad's 
alleged OLE interface in an OLE newsgroup?

Given your list of intended activities in another thread, I would 
recommend you just do the whole thing in Perl, probably using the Tk 
module for text display and editing.  That way your code will still work 
when you get an OS :-).  And you'll get started learning the marvels of 
Tk rather than the slime of OLE.

Finally, if you are really insistent about Notepad, you might look 
around on CPAN.  For example:

http://cpan.org/modules/by-module/Win32/Win32-ActAcc-1.0.readme


 ...


-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 24 Jan 2004 17:13:34 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Win32::OLE Code needed
Message-Id: <4012a125.383663921@news.erols.com>

"edgrsprj" <edgrsprj@ix.netcom.com> wrote:

: It was suggested in an earlier post that I could use Win32::OLE routines to
: control Windows applications instead of using Windows Script Host.

I meant that WSH code can usually be written in Perl.  Whatever object
libraries your WSH program uses to perform its task should be accessible
through Win32::OLE, so translating the program into Perl is mostly a
simple matter of massaging the syntax.

Whether it's worth the effort in your case, I don't know.  

: CONTROL CODES
: 
: Can anyone explain how control codes could be sent to example1.txt while it
: is running?
: 
: For instance, if I want the cursor to move to the end of the file I would
: press and hold Ctrl and then press End on the keyboard.  How could Perl be
: instructed to send that code to notepad?
: 
: Also, how can an Alt code be sent such as Alt F and then S  (save file)?

I smell an X-Y problem.  If your program is opening the app just so it
can remote-pilot some text manipulation steps, you're making things far
more difficult than they should be.



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

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


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