Thank you shmem.
I am to run this perl file from shell for every file in a large corpus (I have to, because this is only a small part of a large project. Execution continues with various other languages and scripts and so on afterwards), not from another perl file. So daxim's highly sophisticated code is unfortunately useless to me.
As you said, "require" would not bring me much advantage because upon finishing execution, even if I do not close() the connection, it will be auto-closed. And while processing the next file, same perl code will be executed and also "require"d file will be executed again.
Roughly, I want to have the following:
db.pl
open2 (\*INP, \*OUTP, 'path_to_external_program');
print "included";
1;
maincode.pl
require "db.pl";
$file = $ARGV[0] #the next file to process
print OUTP some_command_using_$file; #exec some cmds on external prog
#more lines follow afterwards
I want my maincode.pl to function for every file, as well as db.pl to print "included" only once. So that for the whole collection of thousands of documents, I will have only single connection throughout the batch execution. Possible in a way?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.