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?
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
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.
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?
Does file2.pl do a print? What do you mean when you say "it gives me only the last $ip information"?
Hardy Merrill
Mission Critical Linux, Inc.
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?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.