Connecting Tech Pros Worldwide Help | Site Map

subroutine input from external txt file?

Newbie
 
Join Date: Feb 2009
Posts: 4
#1: Feb 12 '09
Hi,

I need to have a Perl script run a query command using ten different input variables that exist in a separate text file and save the output of each query into the same (new) external text file.

Questions:
1. What are the proper Perl terminologies that define my objectives (ie: subroutines, etc.)?

2. Can you direct me to any links that will give me examples / test scripts?

Thanks in advance for your time and assistance.

-TechQA
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#2: Feb 12 '09

re: subroutine input from external txt file?


Quote:

Originally Posted by TechQandA View Post

Hi,

I need to have a Perl script run a query command using ten different input variables that exist in a separate text file and save the output of each query into the same (new) external text file.

Questions:
1. What are the proper Perl terminologies that define my objectives (ie: subroutines, etc.)?

2. Can you direct me to any links that will give me examples / test scripts?

Thanks in advance for your time and assistance.

-TechQA

First, we don't provide test scripts and I don't have any resources for any. This is a learning forum and we will help you when you get stuck.

My first suggestion is that you get a Perl book, like "Learning Perl" and read it and learn Perl. Also, you can reference the perldoc resource as much of the documentation on Perl itself is there at your disposal.

Why don't you try and write something. Then, when you get stuck, post your code here (in code tags) for us to see and point you in the right direction.

Regards,

Jeff
Newbie
 
Join Date: Feb 2009
Posts: 4
#3: Feb 12 '09

re: subroutine input from external txt file?


Hi Jeff,

I have two books: "Learning Perl" and "Perl Core Language Little Black Book". I'm a newbie working on my first script and am more confused the more I read. I understand how this forum works and am not not looking for someone to write a script for me, but any suggestions (and direction assistance) on the correct type of Perl topics I should be reviewing (ie: subroutines, etc.) would be very helpful to me.

Thank you,

-TechQA
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Feb 12 '09

re: subroutine input from external txt file?


Whats a query command?
Newbie
 
Join Date: Feb 2009
Posts: 4
#5: Feb 12 '09

re: subroutine input from external txt file?


I'm writing a Perl script to run queries against a Tivoli TSM (backup system) database to define the status of a list of tape volumes. Each day there will be a different list of tape volume numbers that I need to have this script process (In Perl-speak, I think this is a subroutine that will 'read' the first line of a text file, place it into the query, save the output to a new text file and repeat the process until it has read through all lines of the source text file and appended all the outputs into the same 'new' text file).
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#6: Feb 12 '09

re: subroutine input from external txt file?


Quote:

Originally Posted by TechQandA View Post

I'm writing a Perl script to run queries against a Tivoli TSM (backup system) database to define the status of a list of tape volumes. Each day there will be a different list of tape volume numbers that I need to have this script process (In Perl-speak, I think this is a subroutine that will 'read' the first line of a text file, place it into the query, save the output to a new text file and repeat the process until it has read through all lines of the source text file and appended all the outputs into the same 'new' text file).

If you are interacting with Tivioli, then you may want to look at any of the number of modules on CPAN.

If its a database that you are directly querying, then you want to write perl code using the Perl DBI interface.

I wasn't trying to imply that you don't know how the forum works, I was just giving my standard speech. Why not post the code you are working on (again, in code tags) and we will work with you to get it working.

Regards,

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#7: Feb 13 '09

re: subroutine input from external txt file?


Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. open (my $IN, "<" , 'path/to/queryfile.txt') or die "$!";
  4. while (my $line = <$IN>) {
  5.    chomp $line;
  6.    # here do something with $line
  7. }   
  8.  
Like Jeff said, if you are querying a database you probably want to use the DBI module for the DB interaction stuff. I don't know anything about TiVoli TSM so I can't help there. Search CPAN as suggested.
Newbie
 
Join Date: Feb 2009
Posts: 4
#8: Feb 13 '09

re: subroutine input from external txt file?


Jeff and Kevin,

Thanks for your input and assistance with my post. I'll work on the this over the next week and post a new topic question if/when I have one.

Have a great weekend,

-TechQA
Reply