D
Davy
Hi all,
How to pass hash to subroutine?
And my code list below(it seems the hash has not been passed to sub??):
Code:
#!/usr/local/bin/perl
%mc_mode_hash = ( "00" => "mc_mode_0",
"01" => "mc_mode_1",
"10" => "mc_mode_2");
my $my_cnt = 1;
$my_cnt = &init_cnt_ref(%mc_mode_hash);
print ("my_cnt is $my_cnt \n");
sub init_cnt_ref(\%)
{
#my (%hash0) = %{(shift)};
my %hash0 = %_ ;
my $cnt = 0;
foreach $mc_mode ( values(%hash0))
{
print "mc_mode is $mc_mode \n";
$cnt ++;
}
return $cnt;
}
Thanks!
Davy
How to pass hash to subroutine?
And my code list below(it seems the hash has not been passed to sub??):
Code:
#!/usr/local/bin/perl
%mc_mode_hash = ( "00" => "mc_mode_0",
"01" => "mc_mode_1",
"10" => "mc_mode_2");
my $my_cnt = 1;
$my_cnt = &init_cnt_ref(%mc_mode_hash);
print ("my_cnt is $my_cnt \n");
sub init_cnt_ref(\%)
{
#my (%hash0) = %{(shift)};
my %hash0 = %_ ;
my $cnt = 0;
foreach $mc_mode ( values(%hash0))
{
print "mc_mode is $mc_mode \n";
$cnt ++;
}
return $cnt;
}
Thanks!
Davy