running perl script from inside another script & collecting output in array
running perl script from inside another script & collecting output in array
am 15.09.2011 06:07:31 von Rajeev Prasad
--0-1063279968-1316059651=:67930
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
i am doing like below:
thecalledscript.pl needs a filename as ar=
gument.
here is how i am calling it from a thecalling_script:
=0A=
=0A{
local @ARGV;
@ARGV =3D ("$filename");
=A0=
=A0 require "thecalledscript.pl";=0A}
issue is, the called script prin=
ts some filenames after completion to STDOUT. how can i collect them into a=
n array variable?
--0-1063279968-1316059651=:67930--
Re: running perl script from inside another script & collecting output in array
am 15.09.2011 06:37:46 von Rajeev Prasad
--0-549483615-1316061466=:7570
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
I am now using:
my @outfiles =3D `thecalledscript.pl $filename`;
=
=0Ai am getting right results.
now question is: is this the best metho=
d in terms of efficiency?
=0A________________________________=0 A=
From: Rajeev Prasad =0ATo: Perl Beginners
rl.org>=0ASent: Wednesday, September 14, 2011 11:07 PM=0ASubject: running p=
erl script from inside another script & collecting output in array
=0A=
=0Ai am doing like below:
thecalledscript.pl needs a filename as argum=
ent.
here is how i am calling it from a thecalling_script:
=
{
local @ARGV;
@ARGV =3D ("$filename");
=
require "thecalledscript.pl";=0A}
issue is, the called script prints =
some filenames after completion to STDOUT. how can i collect them into an a=
rray variable?
--0-549483615-1316061466=:7570--
Re: running perl script from inside another script & collectingoutput in array
am 15.09.2011 06:42:08 von Brandon McCaig
On Thu, Sep 15, 2011 at 12:07 AM, Rajeev Prasad wrote:
> here is how i am calling it from a thecalling_script:
*snip*
> Â Â Â require "thecalledscript.pl";
*snip*
> issue is, the called script prints some filenames after completion to STD=
OUT. how can i collect them into an array variable?
You could always make an external call to perl to invoke this program.
For example, using exec or system. E.g.,
exec('perl', 'thecalledscript.pl', $filename);
It depends on just what thecalledscript.pl does and whether or not
your program needs to do anything in response. I'm unfamiliar with
best practices regarding invoking a Perl script with require, but my
intuition says that it looks like abuse. :)
I've sort of begun to think that nearly any program that you write
should be mostly implemented in a library of sorts to optimize the
software-to-software communication between programs. Then you'd just
basically interface that library with the user and standard
input/output mechanisms. If you control thecalledscript.pl then
perhaps you could consider moving the guts into a Perl module, leaving
only the necessary glue in thecalledscript.pl to interface with the
user and/or standard input/output mechanisms.
--=20
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software
..org>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re[2]: running perl script from inside another script & collecting output in array
am 15.09.2011 07:07:48 von jeffpang
CgoKMTUg0YHQtdC90YLRj9Cx0YDRjyAyMDExLCAwODozOCDQvtGCIFJhamVl diBQcmFzYWQgPHJw
Lm5ldWxpQHlhaG9vLmNvbT46Cj4gSSBhbSBub3cgdXNpbmc6Cj4gCj4gbXkg QG91dGZpbGVzID0g
YHRoZWNhbGxlZHNjcmlwdC5wbCAkZmlsZW5hbWVgOwo+IAo+IGkgYW0gZ2V0 dGluZyByaWdodCBy
ZXN1bHRzLgo+IAo+IG5vdyBxdWVzdGlvbiBpczogaXMgdGhpcyB0aGUgYmVz dCBtZXRob2QgaW4g
dGVybXMgb2YgZWZmaWNpZW5jeT8KPiAKCk5vdCB0aGUgZ29vZCB3YXkuCkl0 J3MgYmV0dGVyIHRv
IHdyaXRlIHRoZSBjYWxsZWQgc2NyaXB0IGFzIGEgbW9kdWxlLCB0aGVuIHVz ZSBvciByZXF1aXJl
IHRoaXMgbW9kdWxlIGluIG1haW4gc2NyaXB0IGFuZCBjYWxsIHRoZSBtZXRo b2RzIGluIHRoZSBt
b2R1bGUuCgotLQogIEplZmYgUGFuZwogIGplZmZwYW5nQG1haWwucnUK
Re: running perl script from inside another script & collecting outputin array
am 15.09.2011 15:41:11 von Shawn H Corey
On 11-09-15 01:07 AM, Jeff Pang wrote:
>
>
>
> 15 ÑенÑÑбÑÑ 2011, 08:38 о=D1=
=82 Rajeev Prasad:
>> I am now using:
>>
>> my @outfiles =3D `thecalledscript.pl $filename`;
>>
>> i am getting right results.
>>
>> now question is: is this the best method in terms of efficiency?
>>
>
> Not the good way.
> It's better to write the called script as a module, then use or require=
this module in main script and call the methods in the module.
>
> --
> Jeff Pang
> jeffpang@mail.ru
A better way, IMHO, if you can't move it to a module, is to use `open`.
open my $fh, '-|', 'thecalledscript.pl' or die "could not pipe from=20
thecalledscript.pl: $!\n";
--=20
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
"Make something worthwhile." -- Dear Hunter
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: running perl script from inside another script & collectingoutput in array
am 15.09.2011 16:20:17 von Peter Scott
On Wed, 14 Sep 2011 21:07:31 -0700, Rajeev Prasad wrote:=20
> thecalledscript.pl needs a filename as argument.
>=20
> here is how i am calling it from a thecalling_script:
>=20
>=20
>=20
> {
> Â Â Â local @ARGV;
> Â Â Â @ARGV =3D ("$filename");
> Â Â Â require "thecalledscript.pl";
> }
>=20
> issue is, the called script prints some filenames after completion to
> STDOUT. how can i collect them into an array variable?
You would be better off calling it with backticks. Otherwise you have to=
=20
try fragile techniques such as tying filehandles.
--=20
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/certificates/perl-programming.p hp
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
turnign a script into a perl module
am 15.09.2011 20:58:13 von Rajeev Prasad
--239630641-1970209242-1316113093=:69332
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Based on=A0earlier suggestion by list-members, I think the best way to run =
a script inside a script is to turn the inner script into a module of subro=
utines.
=0AI have few questions:
=0Agiven a sample script style:=
=0A_________________________________________________________ _____=0A#!/usr/=
bin/perl -w=0Ause strict;=0Ause Getopt::Long;=0Ause Net::Telnet;
....i=
declare global variables mostly (i remember fish's suggestion on not using=
, i am reading the best practices page, but too much work...)=0A... i name=
=A0most of my temporary global variables the SAME in different scripts.=0A.=
...has some subroutines of its own.
=0Ascripts will=A0mostly be writing=
to a file or files=0Aprinting names of files written.=0Aend_of_script.=0A_=
____________________________________________________________ _
=0Ahow w=
ould i turn this into a module which can be called from another script? wha=
t type of code should be where? (like perl interpretor/variables/subroutine=
s inside called subroutine)...
=0Athanks for all the advice.=0ARajeev
--239630641-1970209242-1316113093=:69332--
Re: turnign a script into a perl module
am 15.09.2011 21:10:20 von Jim Gibson
On 9/15/11 Thu Sep 15, 2011 11:58 AM, "Rajeev Prasad"
>
scribbled:
> Based on=A0earlier suggestion by list-members, I think the best way to run =
a
> script inside a script is to turn the inner script into a module of
> subroutines.
> =A0
> I have few questions:
> =A0
> given a sample script style:
> ____________________________________________________________ __
> #!/usr/bin/perl -w
> use strict;
> use Getopt::Long;
> use Net::Telnet;
>=20
> ....i declare global variables mostly (i remember fish's suggestion on no=
t
> using, i am reading the best practices page, but too much work...)
> ... i name=A0most of my temporary global variables the SAME in different
> scripts.
> ...has some subroutines of its own.
> =A0
> scripts will=A0mostly be writing to a file or files
> printing names of files written.
> end_of_script.
> ____________________________________________________________ __
> =A0
> how would i turn this into a module which can be called from another scri=
pt?
> what type of code should be where? (like perl
> interpretor/variables/subroutines inside called subroutine)...
Read 'perldoc perlmod', but maybe skip down to the section labeled "Perl
Modules".
Then, read the whole thing and also these:
perltoot
perlboot
perlmodstyle
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: turnign a script into a perl module
am 16.09.2011 02:24:10 von David Christensen
On 09/15/2011 11:58 AM, Rajeev Prasad wrote:
> ... turn the inner script into a module of subroutines. ... how would i turn this into a module which can be called from another script? ...
I'd suggest buying and reading "Intermediate Perl":
http://shop.oreilly.com/product/9780596102067.do
HTH,
David
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/