Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Passing multiple input files to a Perl script through command line

by PKV (Initiate)
on Jun 06, 2018 at 17:39 UTC ( [id://1216041]=perlquestion: print w/replies, xml ) Need Help??

PKV has asked for the wisdom of the Perl Monks concerning the following question:

I am using Getopt function to open 2 separate files with different extensions (.txt and .aspx) in my Perl script by passing single command line argument.

Now, there are many such files of both kinds located in separate folders under the same directory. (Many .txt's in folder text. Same number of .aspx's in folder excel. Folders text and excel are under same directory /pkv/kbv/skv/).

I need to open these files one pair at a time and process them. Then repeat same for remaining pairs (any number). Can I do this by passing command line arguments for the "directory" and "files list"?

use Getopt::Long qw(GetOptions); GetOptions('in=s') or die; $txt = $opt_in . ".txt"; $aspx = $opt_in . ".tab" . ".aspx"; open (TXT, "< $txt") || die; ... close(TXT) open (ASPX, "< $aspx") || die; ... close(ASPX)
  • Comment on Passing multiple input files to a Perl script through command line
  • Download Code

Replies are listed 'Best First'.
Re: Passing multiple input files to a Perl script through command line
by shmem (Chancellor) on Jun 06, 2018 at 17:48 UTC

    Of course you can use more than one command line switch, and you can use command line switches which pass lists. See "Options with multiple values" in Getopt::Long.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Passing multiple input files to a Perl script through command line
by thanos1983 (Parson) on Jun 06, 2018 at 19:19 UTC

    Hello PKV,

    Welcome to the Monastery. An alternative solution is also the module Getopt::Declare that supports loading arguments into array references as well.

    A very nice short example has being given in the forum, read here for more information Getopt::Declare. Minor sample of code bellow:

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found