RE: Running command from string variable as if part of script

2003-12-22 Thread NYIMI Jose (BMB)
I'm wondering if you really need
to read a script into an array ?
Ugly for me ;)

José.

-Original Message-
From: Tushar Gokhale [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 22, 2003 1:36 PM
To: [EMAIL PROTECTED]
Subject: Running command from string variable as if part of script


I'm reading another perl script into array and want to commands from the the array as 
if normal perl commands. How do I do it?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ 
http://learn.perl.org/first-response




 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Running command from string variable as if part of script

2003-12-22 Thread drieux
On Dec 22, 2003, at 5:05 AM, NYIMI Jose (BMB) wrote:
[..]
I'm wondering if you really need
to read a script into an array ?
Ugly for me ;)
[..]

I agree with you, it is clearly not making sense
why one would want that as a pattern - it clearly
can be done:
my $username = 'drieux';
my @alt_cmd = qw/ps -fu/;
my @cmd = qw/ps -aU/;

my @response = [EMAIL PROTECTED] $username`;
foreach my $line (@response)
{
print $line;
}
If anything, the idea of running a hash of arguments
to a command has some value:
my $username = 'drieux';
my $ps_args = {
'broken' = '-fu',
'smallUser' = '-aU',
'bigUser' = '-axwwU'
};
foreach my $key (keys %$ps_args)
{
print running with args: $ps_args-{$key}\n;
my @response = `ps $ps_args-{$key} $username`;
foreach my $line (@response)
{
print $line;
}
}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Running command from string variable as if part of script

2003-12-22 Thread Ajey
my @lines = `cat 2nd_script`;
for each my $line (@lines) {
do something;
}
I guess this should work.I'm presuming that,normal perl commands' means, 
each perl stmt in the script. correct me incaes i'm wrong.



On Mon, 22 Dec 2003, Tushar Gokhale wrote:

 I'm reading another perl script into array and want to commands from the the
 array as if normal perl commands. How do I do it?
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Running command from string variable as if part of script

2003-12-22 Thread Bob Showalter
Tushar Gokhale wrote:
 I'm reading another perl script into array and want to commands from
 the the array as if normal perl commands. How do I do it?

If you want to execute the perl commands in the other script, don't read
them into an array; just do() the script:

   do './myscript.pl';

perldoc -f do

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Running command from string variable as if part of script

2003-12-22 Thread drieux
On Dec 23, 2003, at 1:03 AM, Ajey wrote:
[..]
my @lines = `cat 2nd_script`;
for each my $line (@lines) {
	do something;
}
I guess this should work.I'm presuming that,normal perl commands' 
means,
each perl stmt in the script. correct me incaes i'm wrong.
[..]

thanks for the Thump On the head![1]

What was I thinking when I saw the OP ask:

	I'm reading another perl script into array

Why not use say a perl module??? One of our favorite
perl command - perldoc - is really little more than
a wrapper on Pod::Perldoc - quite literally:
require 5;
use Pod::Perldoc;
BEGIN { $^W = 1 if $ENV{'PERLDOCDEBUG'} }
exit( Pod::Perldoc-run() );
{ for the fun folks should then try
perldoc -m perldoc
perldoc -m Pod::Perldoc
}
Let's start with some basic definitions, that might
make this a bit more obvious:
1. a script is a specific sequence of commands
that may or may not take input and create output
but should do something useful, that is run in
a specific process space when invoked.
2. a sub is a specific sequence of commands
that may or may not take input and create output
but should do something useful, that is run in
the current process space when invoked.
	3. a Perl Module is a way to cache subs for reuse.

4. Refactoring Code - a process by which one takes
already working code and make it slicker and cooler.
So let's start with a simple script 'foo.plx' that does
some basic stuff - it does basically everything that I
need it to do - but then I want to have a piece of code
'bar.plx' which will 'invoke' foo.plx to do some other stuff.
We all know about 'system()', and 'back ticks' and open(),
but what about abstracting the guts of foo.plx into the
Foo.pm so that we then simplify the original foo.plx to
be just like the perldoc you know, do some set up
stuff and then do
	exit(Foo-do_cool(@arglist));

Now in our bar.plx we would want to have

use Foo;

my $got_back = Foo-do_cool(@arglist);
# depending on what we $got_back do some
# other stuff as well...
Just a thought to think about

ciao
drieux
---

[1] the sound you are hearing is
the ringing of a hollow piece of wood!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Running command from string variable as if part of script

2003-12-22 Thread R. Joseph Newton
Tushar Gokhale wrote:

 I'm reading another perl script into array and want to commands from the the
 array as if normal perl commands. How do I do it?

The truly helpful answer would be:  Don't do this!.  OTOH, if you want to try
it out for yourself, I would suggest wrapping in in an eval block.  This will
basically run the script for you.  It will not do anything to compensate for
lack of program structure, though.

Why do you want to run one script from another?  We may be able to find better
ways for you to achieve your purpose.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Running command from string variable as if part of script

2003-12-22 Thread R. Joseph Newton
R. Joseph Newton wrote:

 Tushar Gokhale wrote:

  I'm reading another perl script into array and want to commands from the the
  array as if normal perl commands. How do I do it?

 The truly helpful answer would be:  Don't do this!.  OTOH, if you want to try
 it out for yourself, I would suggest wrapping in in an eval block.  This will
 basically run the script for you.  It will not do anything to compensate for
 lack of program structure, though.

 Why do you want to run one script from another?  We may be able to find better
 ways for you to achieve your purpose.

 Joseph

Just read back through the list.  Is this a continuation of the test harness
thread?  If so, you would get more focused help by staying on-thread.  Reading the
earlier thread showed that there was a purpose, but I still question its
applicablity.  The best test harness for a script is probably the command line.
For any piece of code that can run from the command line on its own, a test harness
is likely to obscure problems and make debugging more difficult, rather than less.

Test harnesses are more appropriate for modules intended for use within a complex
system.  Since each module should, ideally be tested independently, we use test
harnesses to simulate the demands and conditions the module will face when placed
in production, in order to better focus on the problems that arise from other parts
of the application system.

Creating an effective test harness will therefore require some serious high-level
design work.  To be used effectively, a test harness should very closely reflect
the interface of the module, from the calling routine's perspective.  It should
test all boundary conditions that may affect operation, as well as operation under
normal circumstances.  It would be very difficult to do this using a single generic
harness for multiple scripts.  The fan-out should be in the other direction.  Any
large system will probably require many test harnesses in its development, each
specialized to test some portion of the system in isolation.

For any script that can be run from the command line, the interpreter itself shold
be an adequate test harness.  It will provide focused feedback on both the sytactic
integrity of the code, and warnings of likely logic errors.  An interactive
debugger can help, also.  I believe that there is something along that line
available with the standard install of Perl, but I haven't explored it myself.  You
might try:

perldoc perldebug

for more information on the built-in test harness for scripts.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response