Perl command line argument
I have a Perl script that takes each Staff ID as command line argument and
print some info. I would like to do this for 500 staff members - is there any was I could feed a list of ID to the script and ask it to print it? Here's the script (relevant parts only) - #!/usr/bin/perl use Net::LDAP; use DBI; die "Please give Staff ID as argument" if $#ARGV != 0; $staffname = $ARGV[0]; Thanks for any help. |
you can save your IDs in a file, then pass the file to the perl script?
|
Thanks for your help.
I tried - ./staff.pl < file.txt and ./staff.pl file.txt but that didn't work. Is there any other way I can feed input from a file to the Perl script? Thanks, again. |
Quote:
try these: eg Code:
$infile = shift; Code:
$infile = $ARGV[0]; |
Quote:
I don't want to change the Perl script. Is there any way I could do it from the shell? |
Your perl program says:
die "Please give Staff ID as argument" if $#ARGV != 0; But this makes the program stop at line 6 if the number of arguments passed to the perl script is not equal to zero ($#ARGV != 0). I think you really want: die "Please give Staff ID as argument" if $#ARGV = 0; Then you can call the perl script for a set of staff ids from bash with: for item in `cat staffids.txt`; do perl perlprogram.pl $item; done where your list of staff ids is in file staffids.txt and perlprogram.pl is the name of your perl program. |
Quote:
Code:
... |
Ghostdog sounds right to me. You can tell Perl on the command line where to get the file with names saved in it. Here's a variant on the same idea:
Code:
#!/usr/bin/perl Code:
./process_ids id_file |
you can do this, which reads through the command line
as files to open, or pipe a file into the script. It will timeout after 1 second if no arguments or input is forthcoming... Code:
#!/usr/bin/perl |
All times are GMT -5. The time now is 07:11 AM. |