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...

Just a something something...

Replies are listed 'Best First'.
Re^2: hash as subroutine argument
by davorg (Chancellor) on Jul 02, 2009 at 13:17 UTC

    You're reading from the wrong filehandle (a bug you inherited from the original code).

    --

    See the Copyright notice on my home node.

    Perl training courses

      Sorry - didn't run the code, just tried to change the bit they asked about... lesson learned...

      Just a something something...