in reply to Re: powerpoint problem
in thread powerpoint problem

I think that loop would be even more clear this way:

foreach my $i ( 1 .. 4 ) { $slide = $ppt->Slides->Add($i, ppLayoutBlank); }

Replies are listed 'Best First'.
Re^3: powerpoint problem
by NetWallah (Canon) on Apr 24, 2008 at 18:50 UTC
    Agreed. (++)

    To take it to the next step, how about:

    $slide = $ppt->Slides->Add($_, ppLayoutBlank) for 1..4;
    and avoid the (explicit) pesky temporary variable.

    However, for newbies, I'd suggest they stay with my original "C-style for loop" suggestion (to use when they actually need the index variable), until they get more comfortable with perl-style use of $_ for temp vars, and lists generated by the ".." operator.

         "How many times do I have to tell you again and again .. not to be repetitive?"

      I find that with a long statement like that, the modifier gets lost. A casual peruser might not notice there's a loop there at all. It's a little better if the modifier gets its own line like so:

      $slide = $ppt->Slides->Add($_, ppLayoutBlank) for 1..4;

      I like temporary variables too. Usually when $_ appears, it's a comprehension vortex. In this case, the variable ($i) is not much better, but sometimes a good name on a variable can add a lot of documentation. For example,

      foreach my $good_guy ( @ARGV ) { push @my_attr, get_attributes( $good_guy ); }