Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Running a perl script thru a perl script
Hello,

I have built a script that has 2 environment variables passed to it and =
it will take that data and return a value. This script works fine, but =
there are many possibilites that can be passed to it. I want to build a =
test case of sorts to pass to this script. In 'meta-code' this is what I =
would like to do:

@from_numbers =3D qw( "6364421234", "6364421234", "3143221234", =
"3143221234" );
@to_numbers =3D qw( "4225678", "6364425678", "3212222", "3143212222");

while (@from_numbers) {

set environment variable to from_number
set additional variable to to_number
run script

}

My main question: Is there a better way to run the other perl script =
other than running an exec()? I am trying to keep processor usage down =
to a minimum and I know that the exec() function opens up a shell (which =
takes both time, memory, and processor). I dont know if perl has a =
'better' way to handle running another perl script.

A quick explanation of the script that I want to run within this script: =
The script will take a phone 'from phone number' and a 'to phone number' =
and return a value based on the 2 numbers. In trying to fix some things, =
I ended up breaking others. In order to test this manually I have to go =
in, edit the file, then run the script and find the result. I know how =
to go about writing the rest of my test case script, just need to know =
if there is a better way to run the one script within the other, =
hopefully avoiding exec().

Any help is appreciated and if more info is needed, let me know and I =
will supply it.

Thanks,

Dave Kettmann
NetLogic
636-561-0680

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Kettmann
12-22-04 01:55 AM


RE: Running a perl script thru a perl script
Subject: Running a perl script thru a perl script

Hello,

I have built a script that has 2 environment variables passed to it and it
will take that data and return a value. This script works fine, but there
are many possibilites that can be passed to it. I want to build a test case
of sorts to pass to this script. In 'meta-code' this is what I would like to
do:

@from_numbers = qw( "6364421234", "6364421234", "3143221234", "3143221234"
);
@to_numbers = qw( "4225678", "6364425678", "3212222", "3143212222");

while (@from_numbers) {

set environment variable to from_number
set additional variable to to_number
run script

}

My main question: Is there a better way to run the other perl script other
than running an exec()? I am trying to keep processor usage down to a
minimum and I know that the exec() function opens up a shell (which takes
both time, memory, and processor). I dont know if perl has a 'better' way to
handle running another perl script.

A quick explanation of the script that I want to run within this script: The
script will take a phone 'from phone number' and a 'to phone number' and
return a value based on the 2 numbers. In trying to fix some things, I ended
up breaking others. In order to test this manually I have to go in, edit the
file, then run the script and find the result. I know how to go about
writing the rest of my test case script, just need to know if there is a
better way to run the one script within the other, hopefully avoiding
exec().

Any help is appreciated and if more info is needed, let me know and I will
supply it.


########

Not sure I understand your complete requirement but I use a "BEGIN" block to
read a file and set the email address I wish to send a message as the email
address can change and it depending on if I am test or production
environment... (I could have done the same thing without the BEGIN but I
already had the block for other things...)

So the script always sends email to $ENV{Admin} ... and BEGIN block always
reads a file at $ENV{HOME}/email.addrs, parses the file, and set various
$ENV values...

You may wish to read about "Package Constructors and Destructors: BEGIN and
END"


Hope this gives you some ideas ...

jwm

Report this thread to moderator Post Follow-up to this message
Old Post
John Moon
12-22-04 01:55 AM


RE: Running a perl script thru a perl script
Dave Kettmann wrote:
> Hello,
>
> I have built a script that has 2 environment variables passed to it
> and it will take that data and return a value. This script works
> fine, but there are many possibilites that can be passed to it. I
> want to build a test case of sorts to pass to this script. In
> 'meta-code' this is what I would like to do:
>
> @from_numbers = qw( "6364421234", "6364421234", "3143221234", "3143221234"
);
> @to_numbers = qw( "4225678", "6364425678", "3212222", "3143212222");

Erm, you're not using qw() properly.

>
> while (@from_numbers) {
>
> set environment variable to from_number
> set additional variable to to_number
> run script
>
> }
>
> My main question: Is there a better way to run the other perl script
> other than running an exec()? I am trying to keep processor usage
> down to a minimum and I know that the exec() function opens up a
> shell (which takes both time, memory, and processor). I dont know if
> perl has a 'better' way to handle running another perl script.

You wouldn't use exec(), since that replaces your currently running process
with another. You would use system() or backticks. None of these use a shell
unless
you include shell meta-characters.

There's no reason to avoid these calls, IMO. This is the most straightfoward
way to approach it.

I would suggest something like this:

while (<DATA> ) {
($ENV{VAR1}, $ENV{VAR2}) = split;
system('/path/to/myscript.pl');
}

__DATA__
6364421234  4225678
6364421234  6364425678
.. and so on

HTH

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Showalter
12-22-04 01:55 AM


Re: Running a perl script thru a perl script
Dave Kettmann wrote:
> Hello,

Hello,

> I have built a script that has 2 environment variables passed to it and it
> will take that data and return a value. This script works fine, but there
> are many possibilites that can be passed to it. I want to build a test cas
e
> of sorts to pass to this script.

You should probably search for "test" on http://search.cpan.org.

http://search.cpan.org/search?m=module&q=test&s=1&n=100


> In 'meta-code' this is what I would like  to do:
>
> @from_numbers = qw( "6364421234", "6364421234", "3143221234", "3143221234"
 );
> @to_numbers = qw( "4225678", "6364425678", "3212222", "3143212222");

If you had warnings enabled then perl would have warned you about that:

$ perl -le'use warnings; my @x = qw( "1", "2", "3" ); print for @x'
Possible attempt to separate words with commas at -e line 1.
"1",
"2",
"3"

So what you want is either:

my @from_numbers = qw( 6364421234 6364421234 3143221234 3143221234 );
my @to_numbers   = qw(    4225678 6364425678    3212222 3143212222 );

Or:

my @from_numbers = ( 6364421234, 6364421234, 3143221234, 3143221234 );
my @to_numbers   = (    4225678, 6364425678,    3212222, 3143212222 );

Or even:

my @from_numbers = ( '6364421234', '6364421234', '3143221234', '3143221234' 
);
my @to_numbers   = (    '4225678', '6364425678',    '3212222', '3143212222' 
);


And of course, you should probably be using strict as well.


> while (@from_numbers) {
>
> set environment variable to from_number
> set additional variable to to_number
> run script
>
> }

From your pseudo code description, you may want to use an array of arrays or
array of hashes instead, if you want to keep the corresponding from and to
numbers together.


> My main question: Is there a better way to run the other perl script other
> than running an exec()? I am trying to keep processor usage down to a
> minimum and I know that the exec() function opens up a shell (which takes
> both time, memory, and processor).

It only uses a shell in certain circumstances:

perldoc -f exec
[snip]

If there is more than one argument in LIST, or if LIST is an array
with more than one value, calls execvp(3) with the arguments in
LIST.  If there is only one scalar argument or an array with one
element in it, the argument is checked for shell metacharacters,
and if there are any, the entire argument is passed to the
system's command shell for parsing (this is "/bin/sh -c" on Unix
platforms, but varies on other platforms).  If there are no shell
metacharacters in the argument, it is split into words and passed
directly to "execvp", which is more efficient.



John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
12-22-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.