On Wed, May 14, 2014 at 1:31 AM, Mike Dunaway <ekimduna...@gmail.com> wrote:
> What's a good use of references? When is it ideal to use them? Why would you
> want to use them?
>

Maybe a better question is when *not* to use them. I try to keep
things that don't need to be passed around or have multi dimensions to
them (as $arr[5]->[0] looks weird to me vs $arr->[5][0]). Which
basically means that only when I'm returning simple data from a
function is it an array/hash. Even my favorite one liner iptables log
counter uses a reference:
perl -nle 'if (/SRC=([0-9\.]{7,15}) DST=([0-9\.]{7,15})/)
{$ip->{$1}{$2}++}}{ print Dumper($ip)'

A ref also defeats perl's nomenclature of determining your data type -
so then you end up doing ref(\$foo) vs "I know this is an array - perl
wouldn't allow anything else in here, lets go". But, I guess since
native and ref is supposed to run at the same speed, it comes down to
style.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to