Didn't know about 2) and 5) thanks. Looping over the values makes sense as well.
Regards, Le 17/02/2016 15:31, Shlomi Fish a écrit : > Hi Vincent, > > some comments on your code: > > On Wed, 17 Feb 2016 14:24:28 +0100 > Vincent Lequertier <s...@riseup.net> wrote: > >> Thank you for your answer, however I think you have misunderstood my >> problem. I needed to loop over the $groupX in @table while interpolating >> the ip addresses from %vars and displaying the table name. >> But I finally got it to work :-) >> >> I was looking for this kind of lines : >> >> for my $table (@tables) { >> for (0 .. (scalar (@{ $table->{ips} })) - 1) { > > 1. It is a good idea to avoid looping using $_ which can be clobbered very > easily - use a lexical my variable instead. > > 2. scalar(@arr)-1 is more idiomatically written as $#{arr}. > > 3. You're using $table->{ips} more than one time so you should assign it to a > variable. > > 4. Looping over the values of the array will be better than looping over its > indices - at least in this case. > > 5. If your version of perl is recent enough, then you can use keys(@arr) > instead of 0 .. $#arr. > > --- > > For more information, see: > > http://perl-begin.org/tutorials/bad-elements/ > > Regards, > > Shlomi > > >> print $table->{tablename} . ','; >> print $vars{$table->{ips}[$_]}; >> } >> } >> >> >> Thank you anyway > -- Vincent Lequertier skysymbol.github.io -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/