in reply to hash as subroutine argument
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash as subroutine argument
by davorg (Chancellor) on Jul 02, 2009 at 13:17 UTC | |
by BioLion (Curate) on Jul 02, 2009 at 14:02 UTC |