Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: execut perl script for multiple input folders

by vinoth.ree (Monsignor)
on Jul 19, 2013 at 08:57 UTC ( #1045299=note: print w/replies, xml ) Need Help??

in reply to execut perl script for multiple input folders

I guess you have 1000 files in sentence folder want to execute script on each file and create output of each file into output directory with the same input file name?

This post will help you, Input Output Question

Use opendir and readdir with while loop on sentence folder so you will get all the input file names, and pass those input filenames to your as command line argument.

Sample Code:

#!/usr/bin/perl use strict; use warnings; my $directory = '/sentence'; opendir (DIR, $directory) or die $!; while (my $file = readdir(DIR)) { #Run your script here with ``(backtick) or system() } closedir(DIR);

If you want to pass all the 1000 files to your script, in the while loop push each file name into an array then call your script as ` @filenames`

Even you can also use glob to get the list of files from a directory.


Use File::Slurp::read_dir to get the list of files:

use File::Slurp; my @files = read_dir '/sentence';

All is well

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1045299]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2018-06-22 00:14 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.