The other posters already indicate that passing these items as arguments to your subroutine would be the best way to handle it, but I'm looking at your subroutine and wondering what you're trying to do. Just FYI,
<FILE> works line-by-line, so you shouldn't have to split on
\n. You could re-write your function like this:
sub file_processing {
my ($script, $arg, $file) = @_;
my @ret;
open(FILE, "$script $arg $file |") or die "can't do it: $!";
while (<FILE>) {
chomp;
next if /^#|none|unkno/i;
push(@ret, $_);
}
close(FILE);
return @ret;
}
Note also that your
open call is going to be insecure if any of your 3 arguments is provided by the user. You probably want to do something like this for better security, unless you know you can trust all three arguments. Running Perl with taint-checking (-T) enabled helps if you're dealing with potentially bad/mischievous data.
my $pid = open(FILE, "-|");
if (!$pid) {
die "Couldn't fork: $!" unless defined $pid;
exec($script, $arg, $file) or die "Couldn't exec: $!";
}
This has the same effect, but instead of passing the command to
/bin/sh (or whatever your shell is) to parse into a command and arguments (which might include things like semi-colons allowing an evil person to execute other programs), it uses
exec to forcibly pass things as discrete, known arguments directly to the script.
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.