A minor change to your code...
my %MSISDN=(); #populate the subscription list to hash MSISDN open(FILE,"/tmp/subscription_list") || die "Unable to open sub +scription file"; %MSISDN = %{ file_merge(\%MSISDN) }; close(FILE); my %Calls=(); #populate the usage types to hash Calls open(FILE1,"/tmp/Call_Det")|| die "Unable to open call_details +file"; %Calls = %{ file_merge(\%Calls) }; close(FILE1); } sub file_merge { ## take from @_ (the args passed to the subrtn) my $hash_ref = shift; while (<>) { chomp; my ($key, @values) = split /-/, $_; push @{$hash_ref{$key}}, [ @values ]; } return $hash_ref; }
But you would be better off passing in the filepath, doing the reading and parsing in your sub and passing back the hash ref... see below by davorg...
In reply to Re: hash as subroutine argument
by BioLion
in thread hash as subroutine argument
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |