in reply to subroutine no error
Well, because my %CS101 is not a global, its a lexical , lexicals don't have package names, ... what you have there is fake global
This is what you should have written
my %CS101 ... ave(\%CS101); sub ave { my( $cs ) = @_; print "$_\n" for values %$cs; } sub avee { my( $cs ) = @_; for my $k (keys %$cs ){ print $cs->{$k}, "\n"; } }
Subroutines should take arguments, not work with global variables
You should stop using fake globsl , file scope my globals, lexical globals , global lexicals, you're nullifying the helpfulness of strict :) read about it http://perl.plover.com/flagbook/yak/Chi/slide040.html
Tutorials: Variable Scoping in Perl: the basics,
Coping with Scoping , Mini-Tutorial: Perl's Memory Management,
Lexical scoping like a fox,
Read this if you want to cut your development time in half!,
Closure on Closures , perlref#Circular References,
Memory leaks and circular references,
Circular references and Garbage collection.,
make perl release memory,
about memory management , Re^3: Scope of lexical variables in the main script , Re: What's the weaken here for?,
Devel::Cycle,
Devel::NYTProf,
Devel::Leak Devel::LeakTrace,
WeakRef
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: subroutine no error
by adriang (Sexton) on Jul 24, 2014 at 06:08 UTC |