From: "Palit, Nilanjan" <[EMAIL PROTECTED]>
   Date: Thu, 21 Sep 2006 12:14:54 -0700

   How 'bout this:

   my $i= -1;
   map { print "at index '$_->[0]', value='$_->[1]'\n"; } map { $i++; [$i,
   $_] } @array;

   But as before, none of these workarounds are quite as elegant or
   efficient as the implicit "$." semantic ...

   -Nilanjan

I don't follow.  Given that you've already defined "elegant" and
"efficient" as "less code," here's a version of your Verilog parsing
example:

        my $i = 0;
        foreach (@sigs) {
            $mybus{"bus1[$i]"} = $_;
            $i++;
        }

A hypothetical $. would indeed make it more compact:

        foreach (@sigs) {
            $mybus{"bus1[$.]"} = $_;
        }

But using an explicit index is just as compact, though it does require
more tokens:

        for my $i (0..$#sigs) {
            $mybus{"bus1[$i]"} = $sigs[$i];
        }

And Uri's slice assignment is in fact shorter:

        @mybus{ map "bus1[$_]", 0..$#sigs } = @sigs;

Using functional assignment is almost as concise (though it's not
equivalent if %mybus is already populated):

        %mybus = map { "bus1[$_]" => $sigs[$_]; } 0..$#sigs;

Of course, some of this depends on my coding style -- I rewrote all of
these examples the way I normally code so that they could be compared
directly; YMMV, naturally.  But I just don't see the need for another
line-noise variable in Perl.

                                        -- Bob Rogers
                                           http://rgrjr.dyndns.org/
 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to