Le 25/04/2012 09:56, Thierry Vignaud a écrit :
On 24 April 2012 23:17,<[email protected]>  wrote:
fix removing several notebook pages

(...)

--- drakx/trunk/perl-install/diskdrake/hd_gtk.pm        2012-04-24 20:10:47 UTC
(rev 4251)
+++ drakx/trunk/perl-install/diskdrake/hd_gtk.pm        2012-04-24 21:17:30 UTC
(rev 4252)
@@ -285,9 +285,15 @@
      $may_add->(raid2kind()) if @{$all_hds->{raids}};
      $may_add->(loopback2kind()) if @{$all_hds->{loopbacks}};

-    @notebook = grep_index {
-       my $b = $_->{marked} or $notebook_widget->remove_page($::i);
-       $b;
+    my $i = 0;
+    @notebook = grep {
+       if ($_->{marked}) {
+           $i++;
+           1;
+       } else {
+           $notebook_widget->remove_page($i);
+           0;
+       }

Wouldn't have been simpler to decrease $::i instead?
I'm more concerned about the ugly mix between variable affectation ( @notebook = grep {} @list) and additional concerns hidden inside ($notebook_widget->remove_page($i) ). And explicit loop would be easier to understand, and less error-prone:

my @notebook;
my $i = 0;
foreach my $notebook (@list) {
    if ($notebook->{marked}) {
        push @notebook, $notebook;
        $i++;
    } else {
        $notebook_widget->remove_page($i);
    }
}

--
BOFH excuse #136:

Daemons loose in system.

Reply via email to