开发者

Pass values by reference in perl

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜