Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: execut perl script for multiple input folders

by vinoth.ree (Prior)
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

Comment on Re: execut perl script for multiple input folders
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-12-01 07:45 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (795 votes), past polls