Below is the code snippet i have written, here the problem is $server variable cannot be passed inside the subroutines. How can i pass the value of a global variable inside a subroutine. Please help!
use strict;
use warnings;
my (@list,$server);
@list = qw/server1.net server2.net server3.net/;
foreach $server(@list) {
#calling sub-routines
command1();
command2();
}
sub command1 {
print $server;
system("command1");
}
sub command2 {
print $server;
system("command2");
}
$servervariable into the subroutines (command1($server)). But you say "the problem is $server variable cannot be passed inside the subroutines". It would be interesting to here what is preventing you from doing that.foreach (@servers) { func() };the$_in the loop (another server in each iteration) is seen in the subfuncas$_, so the sub is thensub func { $server = $_ ... }. But this is horrible and I hope you can just normally, explicitly and transparently, pass to the function what it needs.