... when i run this script there will be two files that i will be run through this to extract and check data. What i really want to know is if i can use $ARGV[0] for both files if i run them through the subroutine one at a time.
I don't understand this. Do you mean that you will invoke the script twice, with a different file name given each time:
system_prompt>perl your_script.pl file_1
system_prompt>perl your_script.pl file_2
passing a single file name string to the infile() subroutine on each script invocation? Or do you want to invoke the script with two file names at once:
system_prompt>perl your_script.pl file_1 file_2
and process both files during one invocation of the script?
In the first case, two separate invocations of the script, using $ARGV[0] for the file name is fine. In the second case, a single invocation with two file names, you need to realize that the two strings representing the file names will end up in $ARGV[0] and $ARGV[1] respectively, and you must process these two elements of the @ARGV array independently and re-organiize the logic of your script accordingly.
Update: Finally realized that most Perl scripts are invoked not as
script_name.pl parameter_1 param_2 ...
but as
perl script_name.pl parameter_1 param_2 ...
and changed the command-line (pseudo-)code examples above accordingly.
In reply to Re: sending data thru a sub routine
by AnomalousMonk
in thread sending data thru a sub routine
by james28909
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |