perlynewby has asked for the wisdom of the Perl Monks concerning the following question:
need just a quick push to help me get going into passing a multi dimensional hash into a sub...thanks in advance
tim = 40 , 70, 50, 80 john = 98, 97 , 100, 89 eden = 87, 56, 89, 97 pepe = 93 ,91, 94, 90 leah = 100, 99, 99, 100 tony = 89, 94, 100, 89 matt = 68, 70, 75, 73
maybe show me how to pass it by value and ref
use strict; use warnings; use Data::Dump qw(dump); use autodie; my %ave; open my $in,'<', "testscores.txt"; while (<$in>){ my ($name, $score) =split /[\s=s,]+/; for (0..3){ $ave{$name}[$_]=$score; } } #dump \%ave; get_ave(\%ave); #get it by hash_ref my %hash_ref; #why do I have to declare ? sub get_ave{ my $hash_ref =@_; #declared here too? my %hash=%$hash_ref; dump \%hash; #dump \%hash_ref; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing multi dimensional hashes into a sub
by Laurent_R (Canon) on Sep 17, 2015 at 07:36 UTC | |
|
Re: passing multi dimensional hashes into a sub
by poj (Abbot) on Sep 17, 2015 at 06:46 UTC | |
by perlynewby (Scribe) on Sep 17, 2015 at 23:45 UTC | |
by Anonymous Monk on Sep 18, 2015 at 00:17 UTC | |
by perlynewby (Scribe) on Sep 17, 2015 at 23:17 UTC | |
|
Re: passing multi dimensional hashes into a sub
by locked_user sundialsvc4 (Abbot) on Sep 17, 2015 at 11:54 UTC | |
by AnomalousMonk (Archbishop) on Sep 17, 2015 at 19:24 UTC |