my @sorted= @_; #using shift didn't work, why? format? #### use strict; use warnings; use autodie; use Data::Dump qw(dump); open my $in, '<', 'numbers.txt' or die $!; my @data =split/\s+/,<$in>; close $in; my ($mean,$ref,@new_sort)= sort_num(@data); my $length=$$ref; #passing by ref example #print "sorted : @new_sort\n"; print "mean : $mean\n"; print "length : $length\n"; my ($middle,$median)=median_num(@new_sort); print "this is median : $median\n"; print "this will be middle num position : $middle\n"; my ($size,$hash_ref)=mode_num( {NUMBERS=>\@new_sort} ); # my $true_size=$$size; print "this is length :$true_size\n"; foreach my $k (keys %$hash_ref){ for (0..$length){ print " $hash_ref->{$k}[$_]"; #%hash->NUMBER=> i_number #there are undef but dump doesn't show these } } # my sub practice with ref and hash_ref sub sort_num{ our @sorted=sort {$a <=> $b}@_; our $length = scalar (@sorted); our $add_div_elem =(eval join '+',@sorted)/$length; median_num(\@sorted); return $add_div_elem,\$length,@sorted; } sub median_num{ my @sorted= @_; #using shift didn't work, why? format? my $middle_one = eval ((scalar @sorted)+ 1)/2; my $median=$sorted[$middle_one]; return ( $middle_one, $median)# } #passing by references sub mode_num{ my %opt = %{shift @_ } ; #creating hash my $size=keys %opt->{NUMBERS}; #getting size of hash #my %count=(); #for (0..$size){ #have to defined the hash coz perl will see 0 if undef # foreach my $key ( keys %opt->{$key}){ # my $value= $opt->{$key}[$_]; # if (not exists $count{$value}){ # $count{$value}=[]; # } # push $count{$value},$key; # } #} return \$size,\%opt; }