FAQ
Hi List,

I am calling a perl script within another perl script.
What is the best way to pass arguments to the second one ?
Is it possible to pass arrays and hashs (or at least refs) ?
So far I am calling the second script like
@result=`script2.pl $arg1 $arg2 $arg3`
but I guess this is quite ugly.

any help welcome







Patrik Schaub

FMS Internet Service
Friedrichring 8
D 79098 Freiburg
Tel.: +49 761 2926500
Fax: +49 761 2926503
http://www.fmsweb.de

Search Discussions

  • Chas Owens at Jul 10, 2001 at 6:24 pm

    On 10 Jul 2001 20:24:45 +0200, P. Schaub wrote:
    Hi List,

    I am calling a perl script within another perl script.
    What is the best way to pass arguments to the second one ?
    Is it possible to pass arrays and hashs (or at least refs) ?
    So far I am calling the second script like
    @result=`script2.pl $arg1 $arg2 $arg3`
    but I guess this is quite ugly.

    any help welcome
    <snip />
    Well, backticks do variable interpolation (and hence array
    interpolation) so you could say:

    @result=`script2.pl @ARGV`;

    Be careful with this though, if individual elements of the array have
    spaces then they will be treated as seperate options in script2.pl.





    --
    Today is Sweetmorn, the 45th day of Confusion in the YOLD 3167
    Hail Eris!
  • Paul at Jul 10, 2001 at 6:36 pm

    --- "P. Schaub" wrote:
    I am calling a perl script within another perl script.
    Have you looked into require() and do()?
    What is the best way to pass arguments to the second one ?
    Depends on what you want, what it does, and how it's written.
    Is it possible to pass arrays and hashs (or at least refs) ?
    Anything's possible, but not usually the way you'd like.
    If the script is written for it, you could require() it and then call
    it's functions from your own code. Other than that, I don't think
    you're gonna get what you want here.
    So far I am calling the second script like
    @result=`script2.pl $arg1 $arg2 $arg3`
    but I guess this is quite ugly.
    Not necessarily.
    Is it working? Does it beat your machine into whimpering submission?
    If the answers are 'yes' and 'no', then it might be better than trying
    to rewrite the code in script2.pl; on the other hand, if the code in
    script2 is very useful then it might be worth a few hours to wrap it up
    in a module. Then you could rewrite script2 with a few lines, and
    include the same functionality in script1 and script53 with just a few
    lines....and then you probably could share any data in the program,
    like a hash ref. =o)

    __________________________________________________
    Do You Yahoo!?
    Get personalized email addresses from Yahoo! Mail
    http://personal.mail.yahoo.com/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJul 10, '01 at 6:12p
activeJul 10, '01 at 6:36p
posts3
users3
websiteperl.org

3 users in discussion

Paul: 1 post P. Schaub: 1 post Chas Owens: 1 post

People

Translate

site design / logo © 2023 Grokbase