Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: How to pass file paths in a master script which is used to run several perl scripts?

by ankit.tayal560 (Beadle)
on Oct 18, 2016 at 10:39 UTC ( [id://1174196]=note: print w/replies, xml ) Need Help??


in reply to Re: How to pass file paths in a master script which is used to run several perl scripts?
in thread How to pass file paths in a master script which is used to run several perl scripts?

Thanks a lot for the help! appreciate it but If there are 10-20 number of paths which I need to pass on to some 50's of files through the master script. shift can't be used effectively then I guess, any other efficient solutions for that??

  • Comment on Re^2: How to pass file paths in a master script which is used to run several perl scripts?

Replies are listed 'Best First'.
Re^3: How to pass file paths in a master script which is used to run several perl scripts?
by marto (Cardinal) on Oct 18, 2016 at 10:44 UTC

    Consider using a config file and read the values within the child scripts, depending on whatever criteria you have to work with. If you have that many path variables it's worth thinking about this rather than managing then all within a series of scripts.

      Marto, Could you please explain a little bit more about this as I am a beginner to this part of perl scripting. I don't have an idea about how to make config files and all ?? any help is appreciated . Thanks in advance!

        Firstly, we're several posts into this thread and only found out that you have a requirement to deal with up to 20 different paths, with no mention of how you expect the correct paths to be passed to the 50 or so child scripts. What is your criteria for this? Ideally you'd have explained this in your initial post (I've asked you to read this a few times now). There are many ways to use config type files within perl, example.

        "...I don't have an idea about how to make config files..."

        Try Config::Tiny. And please see also Configuration file as well as INI file.

        Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

Re^3: How to pass file paths in a master script which is used to run several perl scripts?
by Monk::Thomas (Friar) on Oct 18, 2016 at 12:37 UTC

    If the provided filenames differ between separate child scripts:

    You can pass the filenames via command line and simply iterate over @ARGV to process them. If the length of the command is getting too long then you could provide the filenames by piping them into the childprocess via STDIN. Or you can write a temp file in the parent script and provide the child scripts with the filename to read from.

Re^3: How to pass file paths in a master script which is used to run several perl scripts?
by RonW (Parson) on Oct 18, 2016 at 22:19 UTC

    2 possibilities come to my mind at the moment:

    If the file paths are not too long, you can pass them as additional parameters to system:

    # master my @files = qw[ path/to/file0 path/to/file1 path/to/file2 ]; system 'perl', 'slave.pl', @files;
    # slave print "List of files to process:\n"; print " $_\n" for (@ARGV);

    If the paths are too long to pass them all as parameters, write them to a file, 1 per line:

    # master my @files = qw[ path/to/file0 path/to/file1 path/to/file2 ]; open my $fh, '>', 'filelist'; print $fh, "$_\n" for (@files); close $fh; system 'perl', 'slave.pl'
    # slave open my $fh, '<', 'filelist'; print "List of files to process:\n"; print while <$fh>; close $fh;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found