Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass arg which is a file

Status
Not open for further replies.

Porshe

Programmer
Jun 5, 2001
38
0
0
US
Hi everyone!
If I have file1.pl that creates a variable $report= $date.pl where $date= local,
how can I open file2.pl and pass it the file name which is stored in $report?

Thanks,
Porshe
 
I'm not sure exactly what you are trying to do, but take a look at the "require" and "do" command documentation. One or the other of them will probably do what you want. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I have in file1.pl this:

system("/export/home/manager/ready/file2.pl", $ip, $report);

system("perl proxy.pl $ip");

Which I believe passes the $ip and $report which $report= $date.pl.

Now, in file2.pl I have:

$report_file_name= $ARGV[0];
open IN, ">>$report" or die "Can't open $report :$!";

I want to append the info from file2.pl to $report. However, I get the file name as the $ip result and it doesn't append to the $report file from file1.pl.

Any ideas?
ps- what does $ip= shift; do?

Thanks a bunch!
 
The function 'shift' returns the first value of an array and shortens it by one. In the line '$ip = shift;', no array is given so @ARGV is used. Here is a look at how @ARGV is changed in file2.pl.
# @ARGV = ($ip, $report);
$ip = shift;
# @ARGV = ($report);
$report_filename = $ARGV[0];
# @ARGV = ($report);

Note that I'm assuming the shift is first. If not then that is what is causing your problem. I would suggest removing the "$ip=shift" and explicity setting the $ip = $ARGV[0] and $report_filename = $ARGV[1];
 
Thanks it works. Except now I have another problem:
I have a loop in file1.pl something like:

foreach my $ip (....) {
....
#this opens my file2.pl
system('export/manager/file2.pl, $ip, $report);
system('perl file2.pl' $ip, $report);
}
In my file2.pl, I have this:
$ip=$ARGV[0];
$report=$ARGV[1];

But when I run it it gives me only the last $ip information. Shouldn't the foreach loop give me one $ip at a time when I pass it to the other script?

thanks,
Porshe
 
When I get to my foreach my $ip loop, it gets about 4 different $ip results. so, each time it goes through the loop the value for $ip changes. When I get to my file2.pl it seems to be reading in only the last value for $ip. But because of the foreach loop I thought system will open file2.pl, read in $ip and $report for each $ip value. But is it because of ARGV[0] that it reads only the last value that is passed into $ip?

 
ok- how about this...
My $ip values are stored in a hash. When I send the argument- $ip to file2.pl I have multiple $ip values but it only prints out my last value that is stored in the hash.

Is there anyway that I can print out all the values that are stored in $ip?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top