I want to pass two values to a function: The name of the hash and the file location.
I have 2 variables $file_location_1
and $file_location_2
. The function is used to create a hash.
My question is: Can I pass the name of the hash and the 2 variables in the function?
enter code here
sub compare
{
open(INFILE,$file)
while<INFILE>
{
%hash{xyz}开发者_StackOverflow社区=pqr;
}
}
compare(\%abc,file_location_1);
compare(\%uvw,file_location_2);
Is this what you want?
sub compare
{
my ($hr,$file) = @_;
open(INFILE,$file);
while<INFILE>
{
$hr->{xyz}=pqr;
}
close INFILE;
}
compare(\%abc,$file_location_1);
compare(\%uvw,$file_location_2);
精彩评论